System Crafters

The 6 Emacs Settings Every User Should Consider

¶ Emacs has a lot of configuration settings!

It can be hard to find the really useful ones without reading through the whole Emacs manual.

In this video I’ll give you a quick tour of 6 configuration settings you will definitely want to try when building your Emacs configuration!

Please make sure to give this video a like 👍 if you learn something useful from it!

¶ Remembering recently edited files

When you do a lot of work with Emacs, you will probably want to get back to files you recently edited. Instead of using find-file to go hunt those files down again, you can enable recentf-mode to have Emacs remember the files you edited most recently:

After enabling this mode, you can use the M-x recentf-open-files command to be shown a list of recent files which can be selected by typing the relevant number. This command isn’t bound to a key by default, so I recommend doing that if you want to use it regularly!

¶ Remembering minibuffer prompt history

One thing you will do a lot in Emacs is enter text into minibuffer prompts. Everything from M-x , isearch , the describe-* commands, and even the shell modes will receive a lot of input from you over time.

You’ll quickly realize that it would be helpful for Emacs to remember the things you’ve entered into these prompts the next time you use them. That’s where the savehist-mode comes in!

When you enable this mode, you will be able to use M-n ( next-history-element ) and M-p ( previous-history-element ) key bindings in almost every minibuffer (and shell) prompt to call up the inputs you used previously for the current command.

I also like to set the history-length to a reasonable number to reduce the impact that reading these history files can have on Emacs’ startup performance.

¶ Remembering the last place you visited in a file

Sometimes it’s convenient for Emacs to remember the last location you were at when you visited a particular file. The save-place-mode can help with that!

Once you turn on this mode, Emacs will drop your cursor to the last visited location in any file that you open.

EmacsWiki: Save Place

¶ Changing the location of the “custom file”

If you’re watching this channel, you’re probably interested in writing your own Emacs configuration mostly by hand without using Emacs’ customization UI. However, even if you avoid using the customization UI, some settings may cause customization variables to be added to your init.el file.

To avoid having Emacs place those variables into your hand-crafted configuration file, you can use this snippet:

Emacs can create a lot of file clutter in your configuration for various reasons, so check out the video I made on the no-littering package if you want an easy way to get that under control!

¶ Prevent using UI dialogs for prompts

Emacs will show prompts to confirm many different types of actions, and for some of them it shows a graphical dialog box. If you prefer to keep your Emacs workflow more keyboard-focused, you can turn off those dialog box prompts with this setting:

¶ Automatically revert buffers for changed files

One thing that can be annoying about Emacs when you first start using it is that it doesn’t automatically refresh file buffers when the file on disk has been changed outside of Emacs. This can often happen when you’re using tools that generate some kind of text file output that you need to read in an Emacs buffer.

The global-auto-revert-mode will make Emacs watch the files for all open buffers for changes on disk and it will automatically refresh those buffers if they don’t have unsaved changes!

I also like adding the following setting to cause other types of buffers in Emacs to update when related files on disk have changed.

The place this is most useful is when you’re using Emacs’ excellent Dired package! The following setting will cause Dired buffers to be automatically refreshed when files get added or deleted from the directory you are browsing:

Check out my video on Dired to learn more!

¶ What are your must-have default settings?

Those are my must-have settings when building up a new Emacs configuration from scratch. If you’ve been using Emacs for a while, leave a comment below and let me know what I might have missed!

Also, if you’re a newer Emacs user and there’s some fundamental behavior you’ve been trying to replicate from another editor, leave a comment and let us know!

  • Route planner

save excursion emacs

Easy hikes and walks in Moscow

Exploring Moscow on foot is a delightful way to connect with nature. To help you make the most of your adventures, we’ve compiled the top easy hikes and walks in Moscow. Perfect for short hikes, kid-friendly excursions, and family-friendly outings, these routes offer something for everyone.

Plan. Save. Navigate. Your best adventures await.

Start today with a free komoot account.

Explore the most popular Tours in Moscow

save excursion emacs

MTB Trails in Moscow

save excursion emacs

Cycling in Moscow

save excursion emacs

Road Cycling Routes in Moscow

save excursion emacs

Running Trails in Moscow

Hiking in Moscow

save excursion emacs

Gravel biking in Moscow

Explore more of Russia : Browse the best Hikes in other regions.

  • Greater Caucasus
  • Krasnodar Krai
  • Republic of Karelia
  • Saint Petersburg
  • Leningrad oblast
  • Stavropol Krai
  • Kaliningrad
  • Karachay-Cherkessia
  • Kabardino-Balkaria
  • Nizhny Novgorod

Next: Customizing Faces , Previous: Changing a Variable , Up: Easy Customization Interface   [ Contents ][ Index ]

50.1.4 Saving Customizations

In the customization buffer, you can save a customization setting by choosing the ‘ Save for Future Sessions ’ choice from its ‘ [State] ’ button. The C-x C-s ( Custom-save ) command, or the ‘ [Apply and Save] ’ button at the top of the customization buffer, saves all applicable settings in the buffer.

Saving works by writing code to a file, usually your initialization file (see The Emacs Initialization File ). Future Emacs sessions automatically read this file at startup, which sets up the customizations again.

You can choose to save customizations somewhere other than your initialization file. To make this work, you must add a couple of lines of code to your initialization file, to set the variable custom-file to the name of the desired file, and to load that file. For example:

You can even specify different customization files for different Emacs versions, like this:

If Emacs was invoked with the -q or --no-init-file options (see Initial Options ), it will not let you save your customizations in your initialization file. This is because saving customizations from such a session would wipe out all the other customizations you might have on your initialization file.

Please note that any customizations you have not chosen to save for future sessions will be lost when you terminate Emacs. If you’d like to be prompted about unsaved customizations at termination time, add the following to your initialization file:

COMMENTS

  1. save-excursion (Programming in Emacs Lisp)

    3.10 save-excursion. The save-excursion function is the final special form that we will discuss in this chapter.. In Emacs Lisp programs used for editing, the save-excursion function is very common. It saves the location of point, executes the body of the function, and then restores point to its previous position if its location was changed.

  2. Excursions (GNU Emacs Lisp Reference Manual)

    31.3 Excursions. It is often useful to move point temporarily within a localized portion of the program. This is called an excursion, and it is done with the save-excursion special form. This construct remembers the initial identity of the current buffer, and its value of point, and restores them after the excursion completes. It is the ...

  3. r/emacs on Reddit: Help understanding save-excursion

    This means that save-excursion cannot do what you want it to if point was within the deleted text, as internally save-excursion stores the position as a marker. Refer to C-h i g (elisp)Excursions which says: Warning: Ordinary insertion of text adjacent to the saved point value relocates the saved value, just as it relocates all markers. More ...

  4. Programming in Emacs Lisp

    4.4.3 save-excursion in append-to-buffer; 4.5 Review; 4.6 Exercises; 5 A Few More Complex Functions. 5.1 The Definition of copy-to-buffer; 5.2 The Definition of insert-buffer. ... Most of the GNU Emacs integrated environment is written in the programming language called Emacs Lisp. The code written in this programming language is the software ...

  5. Why save-excursion doesn't save point position?

    and point is on line 2 between 3 and 4. You write a function that uses save-excursion while it deletes line 1. When the save-excursion ends, point will still be between 3 and 4, although this will now be line 1. The intent is to continue pointing to the same text that it originally pointed to.

  6. Why does this function (that uses save-excursion ...

    Before Emacs 25.1, 'save-excursion' used to save the mark state. To save the mark state as well as point and the current buffer, use 'save-mark-and-excursion'. ... save-excursion just ensures that elisp code acting on a buffer will be able to continue acting afterwards on the same buffer at the same point. Whether or not the window ...

  7. narrowing

    The Emacs Lisp Reference Manual says: 'save-restriction' does _not_ restore point; use 'save-excursion' for that. If you use both 'save-restriction' and 'save-excursion' together, 'save-excursion' should come first (on the outside).

  8. Programming in Emacs Lisp

    The save-excursion function saves the locations of point and mark, and restores them to those positions after the expressions in the body of the save-excursion complete execution. In addition, save-excursion keeps track of the original buffer, and restores it. This is how save-excursion is used in append-to-buffer.

  9. Why does order matter with save-excursion and save-restriction

    And save-excursion says: Save point, and current buffer; execute BODY; restore those things. As the section of the manual explains: If you write them in reverse order, you may fail to record narrowing in the buffer to which Emacs switches after calling save-excursion. So if you have some code like:

  10. emacs save-excursion not restoring point?

    Since you have REPLACE set to t, it replaces all the text and puts point and mark around it, and so point goes to point-min. Furthermore, I think when the spot previously saved by save-excursion is removed Emacs backs up to the beginning of the removed region which again is point-min. I think your solution is fine.

  11. append save-excursion (Programming in Emacs Lisp)

    4.4.3 save-excursion in append-to-buffer. The body of the let expression in append-to-buffer consists of a save-excursion expression. The save-excursion function saves the location of point, ... It enables Emacs to set each variable in its varlist in sequence, one after another; such that variables in the latter part of the varlist can make use ...

  12. On using save-excursion and save-restriction together : r/emacs

    This advice is also present in the documentation for save-restriction. While the book does give a one line explanation- "if save-restriction is used before save-excursion, Emacs may fail to record the narrowing in the buffer it switches to", I don't quite understand it.

  13. Newest 'save-excursion' Questions

    Put "save-excursion" Outermost When Using Both "save-excursion" And "save-restriction". I'm reading Emacs Lisp Intro by Robert J. Chassell. In 6.1 The 'save-restriction' Special Form when you use both 'save-excursion' and 'save-restriction', one right after the other, you should use '... narrowing. save-excursion.

  14. Template for save-excursion (Programming in Emacs Lisp)

    3.10.1 Template for a. save-excursion. Expression. The template for code using save-excursion is simple: (save-excursion. body …) The body of the function is one or more expressions that will be evaluated in sequence by the Lisp interpreter. If there is more than one expression in the body, the value of the last one will be returned as the ...

  15. Why do we use save-excursion inside the copy-to-buffer function?

    I am going through the Emacs Lisp Intro manual to consolidate my Elisp knowledge. In the "More Complex" section, the function "copy-to-buffer" is suggested as a case study. ... (barf-if-buffer-read-only) (erase-buffer) (save-excursion (insert-buffer-substring oldbuf start end))))) Perhaps I do not understand well how the save-excursion works ...

  16. The 6 Emacs Settings Every User Should Consider

    When you do a lot of work with Emacs, you will probably want to get back to files you recently edited. Instead of using find-file to go hunt those files down again, you can enable recentf-mode to have Emacs remember the files you edited most recently: (recentf-mode 1) After enabling this mode, you can use the M-x recentf-open-files command to be shown a list of recent files which can be ...

  17. save-excursion doesn't restore the currently visible buffer?

    8. The current buffer need not be visible in a window. You're looking for save-window-excursion (or quite possibly a combination of the two). n.b. C-u C-h a ^save- will point out all of the following: save-current-buffer. Function: Record which buffer is current; execute BODY; make that. buffer current.

  18. Does anyone ever use save-excursion to preserve the mark?

    Yes, I do use the mark. For example, after you rename a few variables, the original point is not the same text anymore (i.e. buffer could be shrank or expanded). In this case, save-excursion brings me back to correct text - the exact same text regardless of buffer changes - with its mark saving.

  19. Emacs: How to enable a mode globally?

    If Emacs is not working properly with completely stripped down user configuration, or with zero user configuration, then it may be time to back-up your entire installation (to a safe location) and try out the most recent version of Emacs -- if you are up to the challenge, maybe even try out a developer build snapshot.

  20. Easy hikes and walks in Moscow

    Exploring Moscow on foot is a delightful way to connect with nature. To help you make the most of your adventures, we've compiled the top easy hikes and walks in Moscow. Perfect for short hikes, kid-friendly excursions, and family-friendly outings, these routes offer something for everyone.

  21. Saving Customizations (GNU Emacs Manual)

    50.1.4 Saving Customizations. In the customization buffer, you can save a customization setting by choosing the ' Save for Future Sessions ' choice from its ' [State] ' button. The C-x C-s ( Custom-save ) command, or the ' [Apply and Save] ' button at the top of the customization buffer, saves all applicable settings in the buffer.