unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Use emacs.desktop when starting emacs from a particular directory
@ 2018-11-01 15:58 Steinar Bang
  2018-11-01 18:31 ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Steinar Bang @ 2018-11-01 15:58 UTC (permalink / raw)
  To: help-gnu-emacs

Platform: debian 9.1 "stretch", amd64
          emacs 25.1


I would like emacs to use the ~/workspaces/.emacs.desktop when started
in a particular manner by a script, and not use a desktop file otherwise
(when SSH'ing in I would like to restore my development session as much
as possible).

The way I've tried to accomplish it is by starting emacs with the
following commands:
 cd ~/workspaces
 emacs --eval "(progn (setq desktop-path (expand-file-name \"~/workspaces\")) (desktop-save-mode 1))" >/dev/null 2>&1 &

However, the desktop file used is actually ~/.emacs.d/.emacs.desktop and
a ~/.emacs.d/.emacs.desktop.lock file is created as well, and all
emacses started by my user on this computer tries to use the desktop
file (which is not what I want).

Is there a way to accomplish what I'm trying to do?

Thanks!


- Steinar



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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-01 15:58 Use emacs.desktop when starting emacs from a particular directory Steinar Bang
@ 2018-11-01 18:31 ` Eli Zaretskii
  2018-11-02 19:18   ` Steinar Bang
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-11-01 18:31 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Steinar Bang <sb@dod.no>
> Date: Thu, 01 Nov 2018 16:58:45 +0100
> 
> I would like emacs to use the ~/workspaces/.emacs.desktop when started
> in a particular manner by a script, and not use a desktop file otherwise
> (when SSH'ing in I would like to restore my development session as much
> as possible).
> 
> The way I've tried to accomplish it is by starting emacs with the
> following commands:
>  cd ~/workspaces
>  emacs --eval "(progn (setq desktop-path (expand-file-name \"~/workspaces\")) (desktop-save-mode 1))" >/dev/null 2>&1 &

AFAIK, the above is a mistake: desktop-path should be a list of
strings, not a single string.  (I use this feature since time
immemoriam, and it works for me every time.)

P.S. Any variable whose name ends in "-path" signals that it's a list
of directory names.



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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-01 18:31 ` Eli Zaretskii
@ 2018-11-02 19:18   ` Steinar Bang
  2018-11-02 20:23     ` Stefan Monnier
  2018-11-02 21:32     ` Eli Zaretskii
  0 siblings, 2 replies; 13+ messages in thread
From: Steinar Bang @ 2018-11-02 19:18 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Eli Zaretskii <eliz@gnu.org>:

>> The way I've tried to accomplish it is by starting emacs with the
>> following commands:
>> cd ~/workspaces
>> emacs --eval "(progn (setq desktop-path (expand-file-name \"~/workspaces\")) (desktop-save-mode 1))" >/dev/null 2>&1 &

> AFAIK, the above is a mistake: desktop-path should be a list of
> strings, not a single string.  (I use this feature since time
> immemoriam, and it works for me every time.)

Thanks!  I've changed the commands starting emacs to:
 cd ~/workspaces
 emacs --eval "(progn (progn (push (expand-file-name \"~/workspaces\") desktop-path) (desktop-save-mode 1)) (desktop-save-mode 1))" >/dev/null 2>&1 &

Now desktop-path has the following value after startup:
("/home/sb/workspaces" "~/.emacs.d/" "~")
Original value was 
("~/.emacs.d/" "~")

However, emacs still saves and restores state from the
~/.emacs.d/.emacs.desktop file.



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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-02 19:18   ` Steinar Bang
@ 2018-11-02 20:23     ` Stefan Monnier
  2018-11-02 21:08       ` Steinar Bang
  2018-11-02 21:32     ` Eli Zaretskii
  1 sibling, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2018-11-02 20:23 UTC (permalink / raw)
  To: help-gnu-emacs

> However, emacs still saves and restores state from the
> ~/.emacs.d/.emacs.desktop file.

AFAICT the code always saves at the same place where it loaded it.
So if it finds and loads ~/.emacs.d/.emacs.desktop, then it will
save there.

maybe try:
- exit Emacs
- mv ~/.emacs.d/.emacs.desktop ~/workspaces/
- start Emacs


        Stefan "I never actually used it, so the above is only based on
                my understanding of what the code seems to do"




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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-02 20:23     ` Stefan Monnier
@ 2018-11-02 21:08       ` Steinar Bang
  2018-11-02 21:20         ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Steinar Bang @ 2018-11-02 21:08 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Stefan Monnier <monnier@iro.umontreal.ca>:

> maybe try:
> - exit Emacs
> - mv ~/.emacs.d/.emacs.desktop ~/workspaces/
> - start Emacs

It didn't work, unfortunately.

Emacs doesn't use the ~/workspaces/.emacs.desktop and creates a new
~/.emacs.d/.emacs.desktop 



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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-02 21:08       ` Steinar Bang
@ 2018-11-02 21:20         ` Stefan Monnier
  2018-11-02 23:41           ` Steinar Bang
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2018-11-02 21:20 UTC (permalink / raw)
  To: help-gnu-emacs

>> maybe try:
>> - exit Emacs
>> - mv ~/.emacs.d/.emacs.desktop ~/workspaces/
>> - start Emacs
> It didn't work, unfortunately.
> Emacs doesn't use the ~/workspaces/.emacs.desktop and creates a new
> ~/.emacs.d/.emacs.desktop

Can you figure out *when*?  AFAIK Emacs's desktop normally doesn't
choose a desktop file for the user, it should always prompt (or reuse
an existing file).  So the behavior you describe doesn't match
my expectation.  Could it be that you set `desktop-dirname` somewhere in
your customization (maybe in the desktop file itself)?


        Stefan





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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-02 19:18   ` Steinar Bang
  2018-11-02 20:23     ` Stefan Monnier
@ 2018-11-02 21:32     ` Eli Zaretskii
  2018-11-02 23:18       ` Steinar Bang
  1 sibling, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-11-02 21:32 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Steinar Bang <sb@dod.no>
> Date: Fri, 02 Nov 2018 20:18:42 +0100
> 
> >>>>> Eli Zaretskii <eliz@gnu.org>:
> 
> Thanks!  I've changed the commands starting emacs to:
>  cd ~/workspaces
>  emacs --eval "(progn (progn (push (expand-file-name \"~/workspaces\") desktop-path) (desktop-save-mode 1)) (desktop-save-mode 1))" >/dev/null 2>&1 &
> 
> Now desktop-path has the following value after startup:
> ("/home/sb/workspaces" "~/.emacs.d/" "~")
> Original value was 
> ("~/.emacs.d/" "~")
> 
> However, emacs still saves and restores state from the
> ~/.emacs.d/.emacs.desktop file.

First, why do you use 'push' instead of 'setq'?  Don't you want to
replace desktop-path for this invocation?

Second, is there actually an .emacs.desktop file in the ~/workspaces
directory?

Here's what I do for a long time in my .emacs:

  (setq desktop-path '("." ".." "../.." "../../.."))
  (desktop-save-mode 1)

Then starting Emacs in a directory with a .emacs.desktop file reads
that desktop file.  So this feature works, it's just that something in
your case prevents it from working for you.  Perhaps some debugging is
in order.



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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-02 21:32     ` Eli Zaretskii
@ 2018-11-02 23:18       ` Steinar Bang
  0 siblings, 0 replies; 13+ messages in thread
From: Steinar Bang @ 2018-11-02 23:18 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Eli Zaretskii <eliz@gnu.org>:

> First, why do you use 'push' instead of 'setq'?  Don't you want to
> replace desktop-path for this invocation?

Habit I guess... I always treat paths that way: add to the start and
keep the existing value.

> Second, is there actually an .emacs.desktop file in the ~/workspaces
> directory?

Yes.

> Here's what I do for a long time in my .emacs:

>   (setq desktop-path '("." ".." "../.." "../../.."))
>   (desktop-save-mode 1)

> Then starting Emacs in a directory with a .emacs.desktop file reads
> that desktop file.  So this feature works, it's just that something in
> your case prevents it from working for you.  Perhaps some debugging is
> in order.

Right.  Thanks!  Stefan suggested checking my config to see if I had
some (forgotten) desktop setting there.




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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-02 21:20         ` Stefan Monnier
@ 2018-11-02 23:41           ` Steinar Bang
  2018-11-03  3:15             ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Steinar Bang @ 2018-11-02 23:41 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Stefan Monnier <monnier@iro.umontreal.ca>:

> Can you figure out *when*?  AFAIK Emacs's desktop normally doesn't
> choose a desktop file for the user, it should always prompt (or reuse
> an existing file).  So the behavior you describe doesn't match
> my expectation.  Could it be that you set `desktop-dirname` somewhere in
> your customization (maybe in the desktop file itself)?

I found this at the end of my .emacs
;; Only GNU Emacs supports this desktop session restore
(if (not running-xemacs)
    (progn
      (desktop-load-default)
      (desktop-read)))

Annotate says this is from March 12 2002 (but it's probably older.  It's
around the time I organized my RCS versioned config files into a CVS
archive with branches (later transformed in to a subversion repository
and eventually a git repository))

I removed this, moved .emacs.d/.emacs.desktop (from the last session) to
~/workspaces and re-ran the script.

This time I got an error message
 setq: Symbol’s value as variable is void: desktop-path
which is probably push complaining.

I've changed the script to
 cd ~/workspaces
 emacs --eval "(progn (progn (setq desktop-path (list (expand-file-name \"~/workspaces\"))) (desktop-save-mode 1)) (desktop-save-mode 1))" >/dev/null 2>&1 &

Now emacs doesn't have an error message, does not restore any windows,
but on emacs exit:
 1. asks if the desktop files should be written
 2. prompts for the directory to save in, with ~/workspaces as the
    default
 3. says that there is an existing desktop file in this directory, and
    that the current session was not loaded from a desktop file, and
    should it overwrite the file yes/no

I let emacs overwrite the file and restarted using the script.  But the
behaviour was the same.

I'll look more at it tomorrow.

Thanks again!



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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-02 23:41           ` Steinar Bang
@ 2018-11-03  3:15             ` Stefan Monnier
  2018-11-03  8:01               ` Steinar Bang
  2018-11-03  8:03               ` Eli Zaretskii
  0 siblings, 2 replies; 13+ messages in thread
From: Stefan Monnier @ 2018-11-03  3:15 UTC (permalink / raw)
  To: help-gnu-emacs

>  emacs --eval "(progn (progn (setq desktop-path (list (expand-file-name \"~/workspaces\"))) (desktop-save-mode 1)) (desktop-save-mode 1))" >/dev/null 2>&1 &

desktop.el only automatically reads the desktop file if
desktop-save-mode is enabled and only right after reading the init file.
So in the example above, desktop-save-mode is enabled too late but this
to trigger, hence you'd need to explicitly ask desktop to read the file
(by calling `desktop-read`).

BTW, why to you call (desktop-save-mode 1) twice?


        Stefan




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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-03  3:15             ` Stefan Monnier
@ 2018-11-03  8:01               ` Steinar Bang
  2018-11-03  8:03               ` Eli Zaretskii
  1 sibling, 0 replies; 13+ messages in thread
From: Steinar Bang @ 2018-11-03  8:01 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Stefan Monnier <monnier@iro.umontreal.ca>:

>> emacs --eval "(progn (progn (setq desktop-path (list (expand-file-name \"~/workspaces\"))) (desktop-save-mode 1)) (desktop-save-mode 1))" >/dev/null 2>&1 &

> desktop.el only automatically reads the desktop file if
> desktop-save-mode is enabled and only right after reading the init
> file.  So in the example above, desktop-save-mode is enabled too late
> but this to trigger, hence you'd need to explicitly ask desktop to
> read the file (by calling `desktop-read`).

Hm... what I actually want is to use a desktop file if it is in the
directory I'm starting in, but not otherwise.  I guess a subset of Eli's
value would be the right thing of desktop-path would be the right thing.

Should I move the setting back into .emacs instead of the --eval, and
only call (desktop-save-mode 1) if the file is present?

> BTW, why to you call (desktop-save-mode 1) twice?

Copy-paste error.  Thanks for catching it!



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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-03  3:15             ` Stefan Monnier
  2018-11-03  8:01               ` Steinar Bang
@ 2018-11-03  8:03               ` Eli Zaretskii
  2018-11-03  8:40                 ` Steinar Bang
  1 sibling, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2018-11-03  8:03 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Fri, 02 Nov 2018 23:15:59 -0400
> 
> >  emacs --eval "(progn (progn (setq desktop-path (list (expand-file-name \"~/workspaces\"))) (desktop-save-mode 1)) (desktop-save-mode 1))" >/dev/null 2>&1 &
> 
> desktop.el only automatically reads the desktop file if
> desktop-save-mode is enabled and only right after reading the init file.

So perhaps a better solution to the above would be to make some part
of .emacs conditional on some environment variable, and set that
variable in the script?



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

* Re: Use emacs.desktop when starting emacs from a particular directory
  2018-11-03  8:03               ` Eli Zaretskii
@ 2018-11-03  8:40                 ` Steinar Bang
  0 siblings, 0 replies; 13+ messages in thread
From: Steinar Bang @ 2018-11-03  8:40 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Eli Zaretskii <eliz@gnu.org>:

>> From: Stefan Monnier <monnier@iro.umontreal.ca>

>> desktop.el only automatically reads the desktop file if
>> desktop-save-mode is enabled and only right after reading the init file.

> So perhaps a better solution to the above would be to make some part
> of .emacs conditional on some environment variable, and set that
> variable in the script?

That would have been my fallback option, but as it turned out there was
a simpler solution:
 1. Remove my old desktop settings from .emacs
 2. Add the following to the end of .emacs
     (setq desktop-path '("."))
 3. Change the commands in the script starting emacs with a desktop, to:
     cd ~/workspaces
     emacs --eval "(progn (desktop-read)(desktop-save-mode 1))" >/dev/null 2>&1 &

Now emacs started with the script comes up with a restored desktop, but
an emacs started in the home directory with a plain
 emacs &
comes up without desktop restore.

Thanks again!


- Steinar



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

end of thread, other threads:[~2018-11-03  8:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-01 15:58 Use emacs.desktop when starting emacs from a particular directory Steinar Bang
2018-11-01 18:31 ` Eli Zaretskii
2018-11-02 19:18   ` Steinar Bang
2018-11-02 20:23     ` Stefan Monnier
2018-11-02 21:08       ` Steinar Bang
2018-11-02 21:20         ` Stefan Monnier
2018-11-02 23:41           ` Steinar Bang
2018-11-03  3:15             ` Stefan Monnier
2018-11-03  8:01               ` Steinar Bang
2018-11-03  8:03               ` Eli Zaretskii
2018-11-03  8:40                 ` Steinar Bang
2018-11-02 21:32     ` Eli Zaretskii
2018-11-02 23:18       ` Steinar Bang

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