[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

20. Keep Persistent State in Visited Files

This library will make XEmacs keep track of where you were last time you visited a file. It hopes to become a standard and favored XEmacs feature on setups with Berkeley DB installed.

It works by installing functions on the find-file-hooks and on the buffer-local kill-buffer-hook. When a buffer is killed, if it was visiting a file, and place saving has been enabled for it, a database entry is made, saving the location of point. When you visit a file, the database is queried, keyed on buffer-file-name, and if an entry is found, point is set to the value retrieved, and place saving is enabled again for that buffer.

There is a command, which is initially not bound to a keystroke in this incarnation; and may never be, since I think completion works well enough:

 
  M-x toggle-where-was-i 

which, using auto-completion, can be entered as

 
  M-x tog TAB w TAB

that will turn place saving on and off on a per-file, buffer- local basis. If where-was-i-db has been turned off in a buffer and then you kill it, or exit XEmacs, any record for that file will be purged from the database, and you’ll start at the top of the file next time you open it, with place saving turned off there.

Place saving is automatically still ‘on’ when you visit a file you’d toggled it on for in a previous session or visitation. (That’s the point of it, after all.)

Toggling place saving on in a buffer visiting a file is all that is required to cause the where-was-i-db feature to be autoloaded, as toggle-where-was-i will call on install-where-was-i if the ‘wwi-ffh’ has not yet been installed. That WILL NOT cause this feature to be automatically enabled in your next XEmacs invocation, however. For that, you must customize and save wwi-auto-install-on-startup-flag. There is more information about this in its docstring.

This feature can be unloaded with:

 
  C-u M-x install-where-was-i

which will call unload-feature, as well as traverse the buffer-list removing the buffer-local kill-buffer-hook installed by this program. Note that any buffers that got place saving enabled by having had an entry in the database for them when they were first visited (thus restoring point to where it was the last time you had visited the file), will not have an updated entry made, nor the old entry removed (as would happen if you toggle-where-was-i to off in just that buffer), after you uninstall this feature like that.

If you toggle it on again in a buffer visiting a file, then kill that buffer, the point will be saved for it. When you kill the other buffers that had place saving enabled before you uninstalled the feature with C-u M-x install-where-was-i, no where-was-i-db database update will happen for them, since their buffer-local kill-buffer-hook will have been cleaned of the member wwi-save-where-i-am, the function that writes the point entry to the database when a buffer is killed. If you then re-visit one of those files, point will get restored to the location it did the last time you visited that file with where-was-i-db installed.

To remove a file from the place saving database, simply visit it, M-x toggle-where-was-i to switch where-was-i-db off, then kill that buffer. You can see how this works by looking at the definition of wwi-save-where-i-am.

After a period of time, the database of saved file positions will become cluttered with the names of files that no longer exist. You may vacume out the crumbs using:

 
  M-x wwi-vacume-where-was-i-db

which will prompt you for an optional regular expression to match files you want records removed for. It will traverse the database and remove entries for file names that either match the regexp, or that are (not (file-exists-p file-name)). The main reason for this command is the removal of stale entries, for files that no longer exist on the filesystem.

Note also that running wwi-vacume-where-was-i-db will cause EFS traffic, if you’ve saved your place in any remote files. Don’t be surprised if your dialing daemon picks up the phone when you run the vacume function. You should be able to purge the database of all EFS entries with a simple regular expression passed to wwi-vacume-where-was-i-db. Of course, you might not want to do that, for obvious reasons.

To configure this package, type:

 
  M-x customize-group RET where-was-i RET

[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Aidan Kehoe on December 27, 2016 using texi2html 1.82.