I often want to quickly mark everything from point
to the end of line, leaving point
at the same place.
I tried to write simple function for that purpose:
(defun mark-from-point-to-end-of-line ()
"Marks everything from point to end of line"
(interactive)
(save-excursion
(progn
(set-mark-command nil)
(move-end-of-line nil)
(set-mark-command nil)
)))
However, it behaves not as expected, e.g. if you place point over m
in line (move-end-of-line nil)
and execute this command this will mark everything from beginning of buffer to point. I guess this is somehow related to save-excursion
function, but can't be certain. How should I fix that?
P.S. Sorry for question title, don't know how to name it better.
(point)
at each location? There is a notation in the doc-string that states: Novice Emacs Lisp programmers often try to use the mark for the wrong purposes. See the documentation of `set-mark' for more information. Did you fall into the same trap as many of us did when first starting off?set-mark
,set-mark-command
,push-mark
but didn't understand anything. If I eval this sequence it gives me exact what I want — mark region from point to the end of line:(set-mark-command nil)
→(move-end-of-line nil)
→(set-mark-command nil)
. I need it to wrap marked region with parentheses.C-S-(
to wrap marked region and continue typingM-(
, but it's annoying me when I need to wrap something from where point is located to end of line first:C-@ C-e M-(
, basically I want to replaceC-@ C-e
with one shortcut excepting that I have my point untouched. If I removesave-excursion
my function behaves exactly asC-@ C-e C-@