unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>,
	Juanma Barranquero <lekktu@gmail.com>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: RE: calling desktop-read interactively
Date: Thu, 26 Sep 2019 09:20:19 -0700 (PDT)	[thread overview]
Message-ID: <7bd1b73c-cff0-4fae-a1fb-db72fdd41a10@default> (raw)
In-Reply-To: <jwvtv8z84at.fsf-monnier+emacs@gnu.org>

> > 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.



  parent reply	other threads:[~2019-09-26 16:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-26  2:52 calling desktop-read interactively Juanma Barranquero
2019-09-26  7:30 ` Eli Zaretskii
2019-09-26 12:36 ` Stefan Monnier
2019-09-26 12:53   ` Juanma Barranquero
2019-09-26 15:32     ` Stefan Monnier
2019-09-26 16:06       ` Juanma Barranquero
2019-09-26 16:31         ` Eli Zaretskii
2019-09-26 16:52           ` Juanma Barranquero
2019-09-26 16:20       ` Drew Adams [this message]
2019-09-26 16:28       ` Eli Zaretskii
2019-09-26 19:42         ` Stefan Monnier
2019-09-27  4:59           ` Eli Zaretskii
2019-09-27 12:45             ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7bd1b73c-cff0-4fae-a1fb-db72fdd41a10@default \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=lekktu@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).