Hot answers tagged

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


18

There are two cases I can think of: reactivating the region, and adjusting the size of the region. I most often use this binding to reactivate the region after performing some command that deactivates it, or doing something that sets mark and moves point without activating the region. For example, do a C-s and search forward for something. Hit RET to ...


17

Ask Emacs: C-h r i exchange-point-and-mark RET or, better, C-h r i C-x C-x RET. This takes you to the information shown below. This is what the Emacs manual, node Setting Mark says in answer to your question: C-x C-x is useful when you are satisfied with the position of point but want to move the other end of the region (where the mark is). Using C-...


11

I am using Emacs 25.0.50.8 and I noticed the behavior of the save-place variable has been changed: This variable is obsolete since 25.1; use `save-place-mode' instead. You can type C-h v save-place to read its full documentation. Below is my config: (use-package saveplace :init (save-place-mode))


10

That's because when you insert your first chunk of code after start, end remains constant and now point in the middle of something (since more characters have been added before it). A quick solution for your use case is to insert text at the end before: ;; Insert text around a region. In this case, it's ;; the LaTeX code environment from the listings ...


8

The other answers focus on the usefulness of C-x C-x when transient-mark-mode is active. But C-x C-x predates transient-mark-mode, and is useful independently of it. The main role of C-x C-x is to swap point and mark. This useful when you are editing two points in a single buffer and for some reason don't want to split the current window. Do some editing,...


8

I use this when I've lost a selection due to some operation that removed it, and I want to restore selection. One such scenario would be: Select rectangle. Kill it. Undo killing rectangle. C-x C-x to restore selection to rectangle. This happens when I want to make an ad hoc backup of a selected area and to experiment on the copy, such as, for example, I ...


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


6

A very common example of this behavior is electric-pair-mode in the Emacs standard library. If you've never used this mode before, then (quoting from the manual): Whenever you insert an opening delimiter, the matching closing delimiter is automatically inserted as well, leaving point between the two. You can check out the code for electric-pair-post-...


6

Yes, that is the most idiomatic way of inserting text after point that I know of. save-excursion is very resilient to changes in the buffer, so it is the preferred way to do destructive editing. The only place you're likely to run into issues is where you would have issues with insert itself, such as buffers where some text is read-only.


6

Each buffer has a point, and in addition each window also has a point. The manual explains the relationship: The window point is established when a window is first created; it is initialized from the buffer's point, or from the window point of another window opened on the buffer if such a window exists. Selecting a window sets the value of point in ...


6

These are just point and mark right after the yank command. Just see the doc for yank or yank-pop. If you want to conserve these positions you could advice yank. Make sure that you save these values as markers or in buffer-local variables! One more thing: If you want to see these values just once you can call M-: (mark) and M-: (point) right after the yank ...


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

(You say "a region", not "the region", so a guess is that you do not really mean the Emacs region.) If your question is really about the Emacs region then the answer is no. Point (the cursor position) is always at one end of the region, and mark is always at the other end. See the Emacs manual, node Mark for more information. [I found that node by going to ...


5

If your question is what is the use of set-window-point then the answer is that it sets the window-point value for the given window's buffer. See the Elisp manual, node Window Point. It starts by telling you this, which should already answer your question: Each window has its own value of point (*note Point::), independent of the value of point in ...


5

Here is a version using forward-line and move-to-column: (defun pos-at-line-col (l c) (save-excursion (goto-char (point-min)) (forward-line l) (move-to-column c) (point))) Note that next-error has to be able to do that, so you might want to start with functions parsing compilation output...


5

You can use (count-screen-lines &optional beg end count-final-newline window) (manual page) to find the number of lines shown between two points. You can do the following to re-create the point's position on the screen: (let ((lines-down (count-screen-lines nil (point) t)) (lines-from-top-of-window (count-screen-lines (window-start) (point) t)) ...


5

First, you are apparently confusing the mouse pointer with the text cursor (aka cursor). It seems that you mostly talking about the latter, but referring to it as the "cursor". Second, insertion of a character is always between characters (or before the first or after the last character). This is necessarily so, by definition. Even if it were to behave and ...


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

You can use window-absolute-pixel-position: window-absolute-pixel-position is a compiled Lisp function in `window.el'. (window-absolute-pixel-position &optional POSITION WINDOW) Return display coordinates of POSITION in WINDOW. If the buffer position POSITION is visible in window WINDOW, return the display coordinates of the upper/left ...


4

This post provides a work-around, but not an answer to "why does save-excursion not work here?" The problem is interesting. I find org internals to be baroque, and a skim through the source code for org-sort-entries seems to conform with that view. Unless you're deeply interested in the internals, you can use the following work-around to save and restore ...


3

Magit should always do that by default. There was a bug in magit and it was fixed in this commit by @tarsius


3

After running the search, go to match-end. (Included fix from Dan's answer) (when (search-backward-regexp "\n[\t\n ]*\n" nil 'noerror) (goto-char (match-end 0))) From the docstring of search-backward-regexp: See also the functions match-beginning, match-end, match-string, and replace-match.


3

Emacs comes with a timer feature that allows you to run a function in periodical intervals. Some packages abuse this feature by setting their timer intervals very low (around 0.01s) and use it for polling, if they don't manage cleaning up the timers after themselves and leave spurious ones in the timer-list, one after-effect is flickering of letters after ...


3

end is a number, an exact position in the buffer. So when you go to start and insert text, the rest of the text gets pushed forward, and end is no longer pointing to the end of "done" but rather still the position "done" used to be at. The easiest solution is to just insert the end{code} text first, the the begin.


3

Thanks to @nanny! I found the answer in the mailing list which he mentioned in the comment! save-excursion stores a marker, not the 'byte' number. When you kill the line where point is, this marker gets replaced to the beginning of the line. (From: Andreas Politz) From Elisp Manual [ (info "(elisp)Excursions") ]: Warning: Ordinary insertion ...


3

IELM allows you to set another the current buffer, take a look at your Mode Line to see which buffer your IELM is running on, I guess you changed the current buffer. You can change it back with C-c C-b (ielm-change-working-buffer). To learn more info about IELM, type C-h m (describe-mode) as usual.


3

I'm not absolutely sure what is the problem, but your profiler report seems to indicate that posn-at-point performs more redisplay than expected, which in turns causes recomputation of the mode-line, and that powerline should make more effort to memoize its computation for the modeline. IOW, I suggest you M-x report-emacs-bug and you might also report a bug ...


3

If you added a trailing colon to each line like so: /folder/subfolder/file.xml:435: Then enabling M-x compilation-minor-mode will have the desired outcome, such that you can type RET or use mouse-1 to visit the specified file at the specified line. The trailing colon is needed because an error message is expected. In this case the error message (...


2

This advised org-clock-goto will push-mark to the global-mark-ring whenever you are not at the currently clocked item. Otherwise it will jump back to the starting position with pop-global-mark. (NOTE: org-clock-goto will no longer work correctly without an open clock.) (defadvice org-clock-goto (around org-clock-goto--around) "If not at clocked item ...


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