emacs - How to move to the last point position before popping mark-ring? -
i come below scenario:
assumptions: have 5 marks in total: current mark @ position 5, , 4 marks on mark-ring @ positions: 4,3,2,1 respectively. point location somewhere far away, say, 100.
situation: found error @ 4, c-u c-spc<\kbd> jump position 4 , fixed it. forget save previous point position 100. how jump back?
i understand 1 practice save point position before jump. similar jumps happens , in times problem happens 1 or 2 times. once happens, nice if there remedy it, since seems special position too, (last point position before popping mark-ring).
without remedy, seems painful trip manually go position 4 100 manually, happens in low frequency.
the following code adds current position of point mark-ring when invoke c-u c-spc , lets cycle through previous items in mark ring using c-spc (instead of c-u c-spc):
(setq set-mark-command-repeat-pop t) (defadvice set-mark-command (before record-current-position (arg) activate) (when arg (push-mark))) explanation
the advice defined above tells emacs call push-mark function before executing body of set-mark-command command (but if set-mark-command called prefix arg).
push-mark adds current position of mark mark ring , sets mark current position of point.
by setting set-mark-command-repeat-pop non-nil value telling emacs keep popping mark when hitting c-spc right after hitting c-u c-spc.
visual example
based on example gave including visualization of full "round trip" below, where:
x: head of mark ring^: location of mark|: location of point
i'm including example completeness. if don't care going on point, mark, , positions in mark ring behind scenes, can stop reading :)
situation before hitting c-u c-spc:
1 2 3 4 5 ... 100 x ^ |situation after hitting c-u c-spc.
after emacs has evaluated body of
advicedefined above:1 2 3 4 5 ... 100 x ^ |as can see, previous location of mark (
5) has been pushed onto mark ring, , mark @ current location of point (100).after emacs has evaluated body of advised command (
set-mark-command):1 2 3 4 5 ... 100 x ^ |the mark has been popped; since @
100before, point remains @ location. mark @5again.
situation after hitting c-spc first time:
1 2 3 4 5 ... 100 x ^ |locations of
a,^, ,|on subsequent invocations of c-spc:1 2 3 4 5 ... 100 x ^ | 1 2 3 4 5 ... 100 x ^ | 1 2 3 4 5 ... 100 ^ | x 1 2 3 4 5 ... 100 | x ^ 1 2 3 4 5 ... 100 x ^ |
Comments
Post a Comment