emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: calling desktop-read interactively


From: Drew Adams
Subject: RE: calling desktop-read interactively
Date: 2019年9月26日 09:20:19 -0700 (PDT)

> > So, if we were to support multiple filenames, it surely wouldn't just be
> > changing desktop-read to ask for the file name, but fully support multiple
> > desktop files everywhere.
>
> Indeed.
>
> > That's a feature nobody's asked for before, I think.
See below.
> It just seems so weird to only be able to specify the file indirectly via
> the dir in which it lives.
Seems weird indeed. I've never understood the why of
that design.
> It works OK if you have different "desktops"
> for different projects placed in different subdirectories, but if you
> have different "desktops" for different kinds of sessions (e.g. one for
> email, one for programming, ...) then having to place the desktops in
> different subdirectories feels awkward (especially since there isn't
> necessarily many more files to put in those directories).
>
> Being *able* to specify a directory is great. Being limited to that is odd.
Sincere apologies for jumping in here, especially without
reading all of the thread.
FWIW, I have, I'm pretty sure, asked for exactly that feature.
Or at least I've mentioned that it is, IMO, a failing that the
design of desktop.el is _only_ directory-oriented, assuming
that you want/need at most one desktop file per directory.
(Why was such an assumption made? I've never understood it.)
Long ago I implemented this feature - ability to read a
desktop file anywhere, i.e., by file name, in the Bookmark+
code. There, users can have any number of desktop files, in
any directories. They can create bookmarks for them, and so
restore desktops by jumping to bookmarks.
Function `bmkp-desktop-read' reads a desktop file. Maybe it
will help, e.g. by saving a little time, to take a look at
that code. It's in file bookmark+-1.el, here:
https://www.emacswiki.org/emacs/download/bookmark%2b-1.el
Anyway, here is that code:
;; Derived from code in `desktop-read'.
(defun bmkp-desktop-read (file)
 "Load desktop-file FILE, then run `desktop-after-read-hook'.
Return t if FILE was loaded, nil otherwise."
 (interactive)
 (unless (file-name-absolute-p file) ; Should never happen.
 (setq file (expand-file-name file bmkp-desktop-default-directory)))
 (when (file-directory-p file) (error "`%s' is a directory, not a file" file))
 (setq desktop-dirname (file-name-directory file))
 (if (not (file-readable-p file))
 nil ; Return nil, meaning not loaded.
 (let ((desktop-restore-eager t) ; Don't bother with lazy restore.
 (desktop-first-buffer nil)
 (desktop-buffer-ok-count 0)
 (desktop-buffer-fail-count 0)
 (desktop-save nil)) ; Prevent desktop saving during 
eval of desktop buffer.
 (when (fboundp 'desktop-lazy-abort) (desktop-lazy-abort)) ; Emacs 22+.
 (load file t t t)
 (when (boundp 'desktop-file-modtime) ; Emacs 22+
 (setq desktop-file-modtime (nth 5 (file-attributes file))))
 ;; `desktop-create-buffer' puts buffers at end of the buffer list.
 ;; We want buffers existing prior to evaluating the desktop (and not 
reused) to be placed
 ;; at the end of the buffer list, so we move them here.
 (mapc 'bury-buffer (nreverse (cdr (memq desktop-first-buffer (nreverse 
(buffer-list))))))
 (bmkp--pop-to-buffer-same-window (car (buffer-list)))
 (run-hooks 'desktop-delay-hook)
 (setq desktop-delay-hook ())
 (run-hooks 'desktop-after-read-hook)
 (when (boundp 'desktop-buffer-ok-count) ; Emacs 22+
 (message "Desktop: %d buffer%s restored%s%s." desktop-buffer-ok-count
 (if (= 1 desktop-buffer-ok-count) "" "s")
 (if (< 0 desktop-buffer-fail-count)
 (format ", %d failed to restore" desktop-buffer-fail-count)
 "")
 (if (and (boundp 'desktop-buffer-args-list) 
desktop-buffer-args-list)
 (format ", %d to be restored lazily" (length 
desktop-buffer-args-list))
 "")))
 t)))
If something that offers the same thing becomes available
in vanilla Emacs then, at least for the most recent
releases, the Bookmark+ code can just make use of the
vanilla function. If not, that's OK too. HTH.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]

AltStyle によって変換されたページ (->オリジナル) /