5

When I am on a long line, beyond the end of an adjacent line, if I move up or down to the other line the point will go to end of the line, naturally. Then when I move back to the longer line, it goes to the same position I was originally at.

Similarly, if I reach the end of the buffer by pressing down on the last line, when I move up it moves to the column I was in (or the end of the line if the column is from another longer line) rather than the column of the end of the last line.

How does it know what column to move to? This is not goal-column, it is transient (based on the last column explicitly horizontally moved to) rather than permanent.

I would like to control this behavior programmatically, so I would like to know any relevant variables or functions.

  • Have a look at the various variables in simple.el, such as track-eol and line-move-visual. – lawlist Aug 26 '15 at 4:11
6

next-line and previous-line are defined in simple.el, and call line-move. If you take a look at the definition of the function, you'll see that it (as well as line-move-1 and line-move-visual which can be called from line-move) maintain a variable called temporary-goal-column which keeps track of what column point was in when you began line movement.

temporary-goal-column is a variable defined in `simple.el'.
Its value is 1

Documentation:
Current goal column for vertical motion.
It is the column where point was at the start of the current run
of vertical motion commands.

When moving by visual lines via the function `line-move-visual', it is a cons
cell (COL . HSCROLL), where COL is the x-position, in pixels,
divided by the default column width, and HSCROLL is the number of
columns by which window is scrolled from left margin.

When the `track-eol' feature is doing its job, the value is
`most-positive-fixnum'.
  • Thank you - it didn't occur to me to look in the source code, and this wasn't mentioned in C-h f for any of the commands I tried. – Random832 Aug 26 '15 at 3:54
  • Okay, now how can I tell it to actually use it? It uses a hardcoded list of commands and (setq last-command 'next-line) doesn't work. Am I going to need to patch the function, or is there a magic way to override last-command? (EDIT: I think I found it - I have to override this-command) – Random832 Aug 26 '15 at 4:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.