EMACS 24.1.
I need to Rebind Ctrl-space to a custom function that:
- go to end of line
- delete trailing spaces if any
- set the Mark (as normal Ctrl-space)
This is my code not working:
(define-key global-map [?\C- ] 'my-set-mark-command)
(defun my-set-mark-command()
(interactive)
(end-of-line)
(delete-char (* -1 (skip-chars-backward "\t\s")));;delete trailing spaces
(set-mark-command nil))
When no trailing spaces it works normally: start to select and highlight the region.
When trailing spaces: it deletes trailing spaces, stop at end of line, set Mark but don’t highlight the region.
If I remove the last command (set-mark-command) and I run it manually M-xset-mark-command it works.
Please can somebody help me to make this function works properly??
Modification commands cause the variable
deactivate-markto be reset, causing the mark to be lost. In the documentation forsave-excursionit says how to disable that behavior, by binding thedeactivate-markvariable withlet. You can then change the code to:or even include the whole
letinside asave-excursion.See manual:
http://www.gnu.org/software/emacs/manual/html_node/elisp/The-Mark.html#index-deactivate_002dmark-2801