EMACS restoring C-spc disables highlighting

EMACS 24.1. I need Rebind Ctrl-spaceto execute a custom function that:

  • go to end of line
  • remove trailing spaces if any
  • set the sign (as usual 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 there are no trailing spaces, it works fine: start selecting and highlighting a region. When trailing spaces: it removes trailing spaces, stops at the end of a line, sets a label, but does not highlight an area.

If I delete the last command ( set-mark-command) and I run it manually M-x set-mark-command, it works. Please, can someone help me to make this function work correctly?

+2
source share
2 answers

, deactivate-mark reset, . save-excursion , , deactivate-mark let. :

(defun my-set-mark-command ()
   (interactive)
   (end-of-line)
   (let (deactivate-mark)
     (delete-char (* -1 (skip-chars-backward "\t\s"))))  ;;delete trailing spaces
   (set-mark-command nil))

let a save-excursion.

. :

http://www.gnu.org/software/emacs/manual/html_node/elisp/The-Mark.html#index-deactivate_002dmark-2801

+5

, . , C-SPC . C-SPC , . . manual, . C-u C-SPC

+2

All Articles