Different results when the elisp function is executed in different ways; What for?

EDIT: Maybe (in the original post) I misused the term "transitional" (I'm not familiar with jargon yet). I really want to say that the selected region will disappear immediately when the user presses the navigation keys, for example. arrow keys ... (2nd EDIT: I deleted the word "transient")


It’s a particular problem of choosing a region, so that the user receives the movement of the "cursor-key, disappears if the highlight disappears" - this is the last test of my existence. I get different results depending on how I run the following script.

Why does it give different results, or rather, a way to make it create “cursor keys so that the backlight disappears” , regardless of which mode is launched or is it executed during testing? .. CUA mode has this behavior, but I really need to non-CUA mode also did (and, if possible, eval) ...

Here are the results followed by the code. (GNU Emacs 23.1.1)

  • CUA Mode Enabled

    • Rate through Cx Ce - both (call-trans-hi) and (trans-hi)
      NO-GO: both set the mark and move the point to EOL, but nothing is highlighted.

    • Run Mx call-trans-hi
      good: it works fine; the area is highlighted and then disappears the first time you press a key.

    • Via key binding C-f1
      good: it works fine; the area is highlighted and then disappears the first time you press a key.

  • no CUA mode (pretty much std emacs)

    • Rate it with Cx Ce
      NO GO: Same as 1. when CUA is on.

    • Run Mx call-trans-hi
      NO-GO: the line is highlighted, but it is sticky! and requires Cg (keyboard-quit) to clear it.

    • Via key binding C-f1
      NO-GO: the line is highlighted, but it is sticky! and requires Cg (keyboard-quit) to clear it.


  ;test (trans-hi) EOL (defun trans-hi () "transient highlight" (beginning-of-line) (push-mark (point)) (end-of-line) (activate-mark)) ;test (call-trans-hi) EOL (defun call-trans-hi () "call transient highlight" (interactive) (trans-hi)) (global-set-key [C-f1] 'call-trans-hi) 
+4
source share
2 answers

When you look at the activate-mark source, you can see that it simply sets some variables. I suppose why you do not see the mark in 1. , because the actual selection occurs in some materials that are performed when performing functions interactively, and not just call them.

In other cases, without a CUA mode, this is how the temporary backlighting works outside of the CUA mode. If you want CUA mode, use CUA mode accordingly. this part.

EDIT:

This change (adding the setq line) to trans-hi does the highlighting work the way you want?

 (defun trans-hi () "transient highlight" (beginning-of-line) (push-mark (point)) (end-of-line) (setq transient-mark-mode (cons 'only transient-mark-mode)) (activate-mark)) 
+2
source

If you want a region to be highlighted when you check it, you need to activate transient-mark-mode to enable minor transient-mark-mode .

When the area is highlighted, and the default character is to turn off the selection and insert the character into the cursor.

If you want to delete the selected area, activate mode delete-selection-mode .

0
source

Source: https://habr.com/ru/post/1384050/


All Articles