unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* calling desktop-read interactively
@ 2019-09-26  2:52 Juanma Barranquero
  2019-09-26  7:30 ` Eli Zaretskii
  2019-09-26 12:36 ` Stefan Monnier
  0 siblings, 2 replies; 13+ messages in thread
From: Juanma Barranquero @ 2019-09-26  2:52 UTC (permalink / raw)
  To: Emacs developers


[-- Attachment #1.1: Type: text/plain, Size: 138 bytes --]

I've implemented an old FIXME in desktop.el

;; FIXME Interactively, this should have the option to prompt for dirname.

Ok to push this?

[-- Attachment #1.2: Type: text/html, Size: 230 bytes --]

[-- Attachment #2: desktop.patch --]
[-- Type: application/octet-stream, Size: 1889 bytes --]

diff --git i/etc/NEWS w/etc/NEWS
index 9a0b6333e4..79e9655350 100644
--- i/etc/NEWS
+++ w/etc/NEWS
@@ -543,4 +543,9 @@ network connection information (in addition to the host name).
 ** The 'cl' package is now officially deprecated in favor of 'cl-lib'.
 
+---
+** desktop
+*** When called interactively with a prefix arg 'C-u', 'desktop-read'
+now prompts the user for the directory containing the desktop file.
+
 +++
 ** winner
diff --git i/lisp/desktop.el w/lisp/desktop.el
index 59610a128a..498f769bd3 100644
--- i/lisp/desktop.el
+++ w/lisp/desktop.el
@@ -1192,7 +1192,6 @@ desktop-buffer-ok-count
 (defvar desktop-buffer-fail-count)
 
-;; FIXME Interactively, this should have the option to prompt for dirname.
 ;;;###autoload
-(defun desktop-read (&optional dirname)
+(defun desktop-read (&optional dirname ask)
   "Read and process the desktop file in directory DIRNAME.
 Look for a desktop file in DIRNAME, or if DIRNAME is omitted, look in
@@ -1200,7 +1199,9 @@ desktop-read
 is processed and `desktop-after-read-hook' is run.  If no desktop file
 is found, clear the desktop and run `desktop-no-desktop-file-hook'.
+Interactively, with prefix arg \\[universal-argument], ask for DIRNAME.
 This function is a no-op when Emacs is running in batch mode.
-It returns t if a desktop file was loaded, nil otherwise."
-  (interactive)
+It returns t if a desktop file was loaded, nil otherwise.
+\n(fn DIRNAME)"
+  (interactive "i\nP")
   (unless noninteractive
     (setq desktop-dirname
@@ -1210,4 +1211,6 @@ desktop-read
              ;; If DIRNAME is specified, use it.
              (and (< 0 (length dirname)) dirname)
+             ;; Else, with a prefix arg, ask for a directory name.
+             (and ask (read-directory-name "Directory for desktop file: " nil nil t))
              ;; Otherwise search desktop file in desktop-path.
              (let ((dirs desktop-path))

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  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
  1 sibling, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2019-09-26  7:30 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: emacs-devel

> From: Juanma Barranquero <lekktu@gmail.com>
> Date: Thu, 26 Sep 2019 04:52:46 +0200
> 
> I've implemented an old FIXME in desktop.el
> 
> ;; FIXME Interactively, this should have the option to prompt for dirname.
> 
> Ok to push this?

Yes, and thanks.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  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
  1 sibling, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2019-09-26 12:36 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Emacs developers

> +*** When called interactively with a prefix arg 'C-u', 'desktop-read'
> +now prompts the user for the directory containing the desktop file.

Thanks Juanma,

The next step is to allow the user to give the actual desktop *file*
name ;-)


        Stefan




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  2019-09-26 12:36 ` Stefan Monnier
@ 2019-09-26 12:53   ` Juanma Barranquero
  2019-09-26 15:32     ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Juanma Barranquero @ 2019-09-26 12:53 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 743 bytes --]

On Thu, Sep 26, 2019 at 2:36 PM Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> The next step is to allow the user to give the actual desktop *file*
> name ;-)

There's no use case for that. Or, let me put it differently. I think
there's no use case, with the current code, to read from a different
desktop file.

The use case for reading it from different directories is built-in in the
current desktop.el (DIRNAME is passed as an argument back and forth), but
the desktop file name is a defcustom'd variable.

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. That's a feature nobody's asked for before, I
think.

[-- Attachment #2: Type: text/html, Size: 924 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  2019-09-26 12:53   ` Juanma Barranquero
@ 2019-09-26 15:32     ` Stefan Monnier
  2019-09-26 16:06       ` Juanma Barranquero
                         ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Stefan Monnier @ 2019-09-26 15:32 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Emacs developers

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

It just seems so weird to only be able to specify the file indirectly via
the dir in which it lives.  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.


        Stefan




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  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:20       ` Drew Adams
  2019-09-26 16:28       ` Eli Zaretskii
  2 siblings, 1 reply; 13+ messages in thread
From: Juanma Barranquero @ 2019-09-26 16:06 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers

[-- Attachment #1: Type: text/plain, Size: 826 bytes --]

On Thu, Sep 26, 2019 at 5:32 PM Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

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

My use of desktop.el is very simple, so I've never had that problem. I
don't even use desktop files in project directories, just one in ~/.emacs.d/

But for the sessions case you point out, I would definitely create
subdirectories under ~/.emacs.d/desktop-sessions/ or somesuch. Not
particularly awkward, IMO.

> Being *able* to specify a directory is great.  Being limited to that is
odd.

Yes, I agree. It's something to work on, if there's interest.

[-- Attachment #2: Type: text/html, Size: 1086 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: calling desktop-read interactively
  2019-09-26 15:32     ` Stefan Monnier
  2019-09-26 16:06       ` Juanma Barranquero
@ 2019-09-26 16:20       ` Drew Adams
  2019-09-26 16:28       ` Eli Zaretskii
  2 siblings, 0 replies; 13+ messages in thread
From: Drew Adams @ 2019-09-26 16:20 UTC (permalink / raw)
  To: Stefan Monnier, Juanma Barranquero; +Cc: Emacs developers

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



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  2019-09-26 15:32     ` Stefan Monnier
  2019-09-26 16:06       ` Juanma Barranquero
  2019-09-26 16:20       ` Drew Adams
@ 2019-09-26 16:28       ` Eli Zaretskii
  2019-09-26 19:42         ` Stefan Monnier
  2 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2019-09-26 16:28 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: lekktu, emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Thu, 26 Sep 2019 11:32:38 -0400
> Cc: Emacs developers <emacs-devel@gnu.org>
> 
> if you have different "desktops" for different kinds of sessions
> (e.g. one for email, one for programming, ...)

Why would you want that, when Emacs has frames, and each frame can be
set up for different kinds of jobs?

Or, if I turn the table, do you know of any other case or other
software that support reading init-kind of information from a file
whose name can change?



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  2019-09-26 16:06       ` Juanma Barranquero
@ 2019-09-26 16:31         ` Eli Zaretskii
  2019-09-26 16:52           ` Juanma Barranquero
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2019-09-26 16:31 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: monnier, emacs-devel

> From: Juanma Barranquero <lekktu@gmail.com>
> Date: Thu, 26 Sep 2019 18:06:52 +0200
> Cc: Emacs developers <emacs-devel@gnu.org>
> 
> I don't even use desktop files in project directories

I do.  A very useful feature.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  2019-09-26 16:31         ` Eli Zaretskii
@ 2019-09-26 16:52           ` Juanma Barranquero
  0 siblings, 0 replies; 13+ messages in thread
From: Juanma Barranquero @ 2019-09-26 16:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Stefan Monnier, Emacs developers

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

> I do.  A very useful feature.

I'm sure most desktop.el users do.

My point was that I'm particularly inadequate to think how to extend the
desktop feature, because my use of Emacs in general is atypically
simplistic: one frame (two on very specific occasions), no speedbar, no
toolbar, few windows. And I don't keep Emacs running for long or use it in
daemon mode. I usually start Emacs many, many times a day.

[-- Attachment #2: Type: text/html, Size: 517 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  2019-09-26 16:28       ` Eli Zaretskii
@ 2019-09-26 19:42         ` Stefan Monnier
  2019-09-27  4:59           ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2019-09-26 19:42 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: lekktu, emacs-devel

>> if you have different "desktops" for different kinds of sessions
>> (e.g. one for email, one for programming, ...)
> Why would you want that, when Emacs has frames, and each frame can be
> set up for different kinds of jobs?

I always have 2 Emacs sessions running, one for email and one
for programming.  Each session uses many frames.  I use separate
sessions for them because I don't want to have one operation block
the other (mostly: my email-session being blocked while
sending/receiving messages).


        Stefan




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  2019-09-26 19:42         ` Stefan Monnier
@ 2019-09-27  4:59           ` Eli Zaretskii
  2019-09-27 12:45             ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2019-09-27  4:59 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: lekktu, emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: lekktu@gmail.com,  emacs-devel@gnu.org
> Date: Thu, 26 Sep 2019 15:42:48 -0400
> 
> >> if you have different "desktops" for different kinds of sessions
> >> (e.g. one for email, one for programming, ...)
> > Why would you want that, when Emacs has frames, and each frame can be
> > set up for different kinds of jobs?
> 
> I always have 2 Emacs sessions running, one for email and one
> for programming.  Each session uses many frames.  I use separate
> sessions for them because I don't want to have one operation block
> the other (mostly: my email-session being blocked while
> sending/receiving messages).

Starting Emacs from different directories for each session should
satisfy this use case.  Although I don't think I understand why the
email session needs a desktop file anyway -- what important
information is saved in that desktop file?



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: calling desktop-read interactively
  2019-09-27  4:59           ` Eli Zaretskii
@ 2019-09-27 12:45             ` Stefan Monnier
  0 siblings, 0 replies; 13+ messages in thread
From: Stefan Monnier @ 2019-09-27 12:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: lekktu, emacs-devel

> Starting Emacs from different directories for each session should
> satisfy this use case.

Indeed, as I said, you can always use "artificial" directories.
It just seems like an unnatural restriction.

> Although I don't think I understand why the email session needs
> a desktop file anyway -- what important information is saved in that
> desktop file?

The shape and position of the frames, as well as a few files I use to
handle the review of admissions requests (which are mostly processed
via email exchanges).


        Stefan




^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-09-27 12:45 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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