Reputation: 3127
I use desktop sessions to save project state between loads. Sometimes I am working on a feature that is shared between a few buffers, and would love to assign a quick keyboard shortcut like -# to a buffer. Then I could switch between a fe buffers by hitting cmd-1, cmd-2, cmd-3, etc. Thoughts?
Thanks!
Upvotes: 1
Views: 259
Reputation: 30708
If you use Bookmark+ then you can use desktop bookmarks. "Jumping" to such a bookmark restores the saved desktop - each bookmark refers to a particular desktop file. Bookmarks are persistent.
A bookmark name can use any characters - it could be 1
or 9
or 312
. You can bind a single key (including a digit key, if you like) to the command that jumps to a bookmark whose name you enter (with completion).
You can also easily define a command that jumps to a given bookmark. And you can bind such a command to any single key you like: 1
, 2
,... or -1
, -2
,... (though that might not be a great idea ;-)).
(FWIW, a command name must be a symbol name, a symbol name must have symbol characters, and it cannot have the syntax of a number (which 2
and -2
do). So you could name commands a1
, a2
,... or _1
, _2
,... or -a1
, -a2
,.... But you are anyway unlikely to call such commands by their names.)
UPDATE
If you just want to switch/navigate among the files or buffers of a project, without closing other buffers etc. then look for project-support Emacs features and extensions. There are plenty available, including some (such as Dired) that come with vanilla Emacs.
With Bookmark+, for example, you can use bookmarks of various types, including the following, to help manage software projects:
Dired buffers, with specific sets of files and subdirectories that are marked or omitted, and using specific listing switches.
*Bookmark List*
buffers, with specific sets of bookmarks that
are marked or hidden.
Multiple alternative bookmark files. For example, use a different one for each project. Or use different ones for subprojects and use them together for a full project.
DeskTops (already mentioned), which include sets of variables and visited buffers and files.
Sequence bookmarks, which combine other bookmarks.
You can also associate tags, in the delicious sense, with most types of bookmarks. (Such tags are unrelated to the Emacs source-code tags that use TAGS files.) A bookmark can have any number of tags, and multiple bookmarks can have the same tag, which means you can use them to organize their target objects. And tags can be more than just names: they can be user-defined attributes, with Emacs-Lisp objects as their values.
These and other Bookmark+ features give you different ways to save, restore, filter, access, and otherwise organize projects, as collections of information about source-code components and related software.
Icicles enhances access to such Bookmark+ features, and it provides additional project-support features.
Upvotes: 0
Reputation: 20352
I'm using this code for this purpose:
(require 'bookmark)
(defvar zz-minibuffer-map (copy-keymap minibuffer-local-must-match-map)
"Keymap for `bookmark-do-quick-jump'")
(define-key zz-minibuffer-map
[remap self-insert-command] 'zz-self-insert-complete-and-exit)
(define-key zz-minibuffer-map " " "-")
(defvar zz-display-function nil)
(defun zz-self-insert-complete-and-exit (n)
(interactive "p")
(self-insert-command n)
(ignore-errors
(completion--do-completion nil 'expect-exact))
(let ((candidates (completion-all-sorted-completions)))
(cond
((null candidates)
(backward-delete-char-untabify 1)
(minibuffer-complete))
((eq 1 (safe-length candidates))
(minibuffer-complete-and-exit)))))
;;;###autoload
(defun zz-bookmark-jump (bookmark)
"Jump to specified bookmark with auto-completion and auto-acceptance."
(interactive
(list
(if (window-minibuffer-p)
(error "Already in minibuffer")
(let ((minibuffer-local-must-match-map zz-minibuffer-map))
(completing-read "Jump to bookmark: " bookmark-alist nil t)))))
(ignore-errors
(bookmark-jump bookmark zz-display-function)))
Just bind zz-bookmark-jump
to what you want, say M-m.
Now, if you name a bookmark as 1...
, where ...
is anything you want, and no other
bookmarks start with 1
, M-m 1 will jump to that bookmark.
Here are some of my bookmarks for reference:
b: .bashrc ~/.bashrc
e: .emacs ~/.conf.d/.emacs
h: hooks.el - no file -
L: main.cc ~/Dropbox/source/c++/lattice/main.cc
m: magit - no file -
q: *scratch* - no file -
s: source ~/Dropbox/source/
I like to add :
to make them look nice visually when I call bookmark-bmenu-list
.
Upvotes: 1