I have found an answer to my question through narrowing down the naughty bit and googling. I have managed to reduce the lag 10 TIMES!!!! I mean....It is insane on how much computing power next-line was using to move a cursor down ?!?!
Put this code into your init.el: (setq auto-window-vscroll nil)
Now next-line does not trigger line-...
The misc package (shipped with emacs) has the built-in function forward-to-word, which does what I think you want:
forward-to-word is an interactive compiled Lisp function in `misc.el'.
It is bound to M-f.
Move forward until encountering the beginning of a word.
With argument, do this that many times.
To use it, first add (require ...
You have two three options:
Use next-logical-line instead of next-line when defining the macro:
Move cursor vertically down ARG lines.
This is identical to next-line, except that it always moves
by logical lines instead of visual lines, ignoring the value of
the variable line-move-visual.
Set line-move-visual to nil:
(setq line-move-visual nil)
You can try setting scroll-preserve-screen-position to always:
(setq scroll-preserve-screen-position 'always)
From the documentation (C-h v scroll-preserve-screen-position):
Controls if scroll commands move point to keep its screen position unchanged.
A value of nil means point does not keep its screen position except
at the scroll margin or window ...
I don't know of a package that would enable this behavior, but here's one way to do it.
Press C-h k C-a to discover that C-a is bound to move-beginning-of-line; this is the function we need to modify --- or just use to implement the "moving to the beginning" part. Similarly, with C-h k I can find forward-line, which will be used to move up/down.
To be able ...
You need to modify the line-move-visual variable.
You need to set its value to nil if you want the up/down line navigation happen logically (not visually).
When line-move-visual is set to nil
▮his is a very very very very very long line
and it wrapped around here.
This is the next line
After hitting C-n (moving the cursor to the next line) ..
This is a ...
This was a pretty cool question, I learned a lot that I didn't know while trying to figure this out. What I learned was that each window has its own value for point. This is important because it means that the point is not associated with the buffer but instead the actual window. As we've seen this makes a big difference.
What we need to do then is set the ...
M-C-f (or M-C-right) bound to forward-sexp should do that.
I suggest you try all well-known motion commands with the prefix M-C- instead of C-.
M-C-b (or M-C-left) gives backward-sexp
M-C-u (or M-C-up) gives backward-up-list
M-C-n (or M-C-down) gives forward-list
Library misc-cmds.el has long had this feature.
These are the relevant commands, and suggested key bindings (these bindings are made in setup-keys.el).
(cond ((fboundp 'move-beginning-of-line)
(substitute-key-definition 'move-beginning-of-line 'beginning-of-line+ global-map)
(substitute-key-definition 'move-end-of-line 'end-of-line+ global-...
(This is too long for a comment, and while not literally an answer, I hope it might help the OP.)
While Drew's answer covers what you literally want, this is probably not what you need. Point in Emacs is never on a character, it is between characters:
Like other positions, point designates a place between two characters
(or before the first character, ...
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.
Consider to customize variable org-special-ctrl-a/e. Possibly that will ease your flow.
From the documentation. Note in particular the "item" part.
When t, ‘C-a’ will bring back the cursor to the beginning of the
headline text, i.e. after the stars and after a possible TODO keyword.
In an item, this will be the position after bullet and check-box, ...
I think post-command-hook is what you wish to use.
It is run every time a command has been run. And a command is basically any interactive action, such as clicking a mouse button, typing a letter (which runs self-insert-command, or running a command using M-x.
You may wish to make sure your hook is not run while you are typing in the minibuffer. I think ...
This feature exists in Emacs. Outline mode describes a document as containing heading lines with a level, and has facilities to move among levels. We can define every line as a heading line with a level that reflects its indentation: set outline-regexp to the indentation. More precisely, the indentation plus the first non-whitespace character (and the ...
(Jules Tamagnan's answer identifies the problem, I'll expand on it.)
Your solutions with save-excursion or save-excursion do in fact work! You can see it by checking the value of (point) in that buffer afterwards, e.g.
always returns 42 (...
Load library simple.el (not simple.elc), then do M-x debug-on-entry RET next-line RET.
Then use C-n and step through the debugger using d (or c to skip through an evaluation) to see what happens (when the flickering occurs etc.). If the flicker happens during evaluation of a function call for a function that is not defined in simple.el, you can load its ...
Since the answer is picked from the comment from @kaushalmodi, I cannot choose the comment as an answer, so I post this as the right answer.
According to comment from @kaushalmodim, syntax-subword is great, it is exactly what I need. You can install it using package.el.
Here is my configuration in init.el:
Bind C-e to a command that puts the cursor one char to the left of the line end.
(defun foo (arg)
(unless (bolp) (backward-char)))
(global-set-key "\C-e" 'foo)
(Although I cannot imagine why you would want to move the cursor there.)
The following three commands, minimally tested, should allow for basic navigation by indented lines. Apologies for the code repetition.
(defun ind-forward-sibling ()
"Move forward to the next sibling line with the same indentation."
(let ((col (current-column))
The following function moves the cursor to the middle of the current line:
(defun my/move-to-middle ()
(let* ((begin (line-beginning-position))
(middle (/ (+ end begin) 2)))
You can bind this to a key (I used C-c m) using
(global-set-key (kbd "C-c m") 'my/move-to-middle)...
Here's a quick command, lightly tested, that does what you're looking for.
(defun eol-dwim ()
"Go to the end of the line, ignoring comments and trailing
(let ((bol (line-beginning-position 1))
(eol (line-end-position 1)))
(if (condition-case nil
You can use skip-syntax-forward to skip non-whitespace. Docstring:
(skip-syntax-forward SYNTAX &optional LIM)
Move point forward across chars in specified syntax classes.
SYNTAX is a string of syntax code characters.
Stop before a char whose syntax is not in SYNTAX, or at position LIM.
If SYNTAX starts with ^, skip characters whose syntax ...
If you want to write your own use the contents of (syntax-ppss (point)) which you give you the positions of matching pairs in the current context amongst other data. Read the docs for syntax-ppss for more info.
But you don't need to implement the function, you can use forward-sexp and backward-sexp to jump between matching pairs. bound by default to C-M-f ...
You can bind the below function to M-f and bind the original forward-word to M-F. This function simply takes the arg and passes it on to the forward-word function. So the universal arguments will work just as fine as with the original function.
(defun modi/forward-word-begin (arg)
"Move forward a word and end up with the point being at the beginning of ...
Could someone explain this behavior?
The documentation of line-end-position has a note at the end that explains this behavior:
This function constrains the returned position to the current field
unless that would be on a different line than the original,
unconstrained result. If N is nil or 1, and a rear-sticky field ends
at point, the scan stops ...
Examining the four answers available currently (two on Super User and two on this question), I see the following issues:
The ones on SuperUser by Stefan and Peng Bai (moving line-by-line, looking at current indentation) don't implement retaining the current column position and moving up to the parent,
The answer by Dan (using re-search-forward to find next ...