2009-05-09

remembering your position in a file

A little useful trick I recently discovered is SavePlace. Adding

(setq save-place-file "~/.emacs.d/saveplace") ;; keep my ~/ clean
(setq-default save-place t)                   ;; activate it for all buffers
(require 'saveplace)                          ;; get the package
to your .emacs will make emacs remember where you were in a file, the last time you opened ('visited') it; when you re-open it, it jumps right back to where you were. The set-default enables saveplace (which is buffer-local) for all buffers.

There are some more customizations possible, but they seem less useful to me.

SavePlace is the kind of nice convenience that make emacs so nice… at the same time, it shows that so many of these small conveniences can go unnoticed for years (saveplace has been part of Emacs since version 19.19 of 1993!).

10 comments:

Anonymous said...

Is there a special reason why you put the require-statement last? I used to put it first. Might not make a difference, just wondering.

djcb said...

@Anonymous: I guess that if you don't set 'save-place-file' beforehand, saveplace, /might/ use its default.

whether that's really a problem depends on how saveplace implements this (when it loads the save-place-file).

James said...

Menu: Options->Save Place in Files Between Sessions

djcb said...

@James: clever :) never occured to me.

anyway, I think I prefer the manual solution because:
- don't want to clutter my .emacs with the emacs customization stuff
- i'd like to keep the saveplace-file outside ~/
- i don't use the menu

Tom said...

looks useful, thanks!

Tushar said...

Thanks for the tip; I have been looking for this from a long time.

Erik said...

@djcb: There's a nice solution to the clutter by customize, if you happen to like the interface of M-x customize (which I do, because it makes so many more emacs settings discoverable): just add something like

(setq custom-file "~/.emacs.d/my-custom-file.el")
(load custom-file)

to your .emacs. If you have any customize settings, move them to that file manually. This keeps .emacs nice and clean while still allowing the use of M-x customize.

djcb said...

@Erik: yes, that is a good tip. I should start using that -- sometimes still programs dump stuff in my .emacs.

dismantr said...

I don't manage to have saveplace working in emacs 23 used in daemon mode (server) with the following lines in my .emacs:

(setq
save-place-file (concat emacs-tmp-dir "/saveplace")
save-place t ; save position in files
)
(require 'saveplace)

It's working when I do not use emacsclient (emacs23 command only) but nor with the server...

Any idea?

Anonymous said...

Thanks a lot.. I have been dying without this.. and kind off missing my VI

-Sachin Dangol