Hot answers tagged

23

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. (forward-to-word ARG) Move forward until encountering the beginning of a word. With argument, do this that many times. To use it, first add (require ...


21

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 ?!?! The fix: Put this code into your init.el: (setq auto-window-vscroll nil) The proof: Now next-line does not trigger line-...


13

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) ...


12

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 ...


12

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 ...


9

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 ...


9

Depending on what is that number, e.g., 47 (line, character-position, etc) you can do M-x goto-line 47 or M-x-goto-char 47.


9

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


8

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-...


8

(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, ...


8

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 ...


6

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 ...


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. ...


5

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 ...


5

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." (interactive) (save-match-data (let ((col (current-column)) (pad (progn (back-to-...


5

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 ...


5

Bind C-e to a command that puts the cursor one char to the left of the line end. (defun foo (arg) (interactive "p") (end-of-line arg) (unless (bolp) (backward-char))) (global-set-key "\C-e" 'foo) (Although I cannot imagine why you would want to move the cursor there.)


5

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 ...


5

(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. (progn (with-current-buffer "*whatever*" (goto-char 42)) (with-current-buffer "*whatever*" (point))) always returns 42 (...


5

The following function moves the cursor to the middle of the current line: (defun my/move-to-middle () (interactive) (let* ((begin (line-beginning-position)) (end (line-end-position)) (middle (/ (+ end begin) 2))) (goto-char middle))) You can bind this to a key (I used C-c m) using (global-set-key (kbd "C-c m") 'my/move-to-middle)...


5

You can run the command isearch-edit-string pressing M-e. See the documentation for details.


5

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 whitespace." (interactive) (let ((bol (line-beginning-position 1)) (eol (line-end-position 1))) (if (condition-case nil (comment-search-forward eol) (error nil)) ...


5

This can be done using save-excursion, then moving the cursor. (defun point-calc-lines-offset (pt lines) (save-excursion (goto-char pt) (forward-line lines) (point))


4

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 ...


4

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 ...


4

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: (global-syntax-subword-mode) (setq syntax-subword-...


4

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 ...


4

This is supported right out-of-the-box, by setting: (setq org-special-ctrl-a/e t) As a bonus C-e handles tags similarly to C-a handling asterisks.


4

Use C-M-a (beginning-of-defun) to move backward before each "defun" (top-level sexp). Use C-M-e (end-of-defun) to move forward after each "defun". To move across several by repeating, just hold down Control, Alt (Meta), and a or e. To move forward/backward N defuns, use a numeric prefix arg. E.g. C-u 1 0 C-M-e moves forward 10 defuns. (There are several ...


3

(forward-line 1) will take the point to the next line. You can learn more about that and other motion commands from here.


Only top voted, non community-wiki answers of a minimum length are eligible