一些 emacs 桌面保存问题:如何更改为保存在 ~/.emacs.d/.emacs.desktop

发布于 2024-10-08 09:28:18 字数 250 浏览 8 评论 0原文

我在 init.el 中设置了这个设置

(desktop-save-mode 1)

,效果很好,只是我想知道:

  • 如何更改它以将 .emacs.desktop 文件保存到 ~/.emacs.d 而不是 ~/

  • 如何阻止它询问我是否要保存(仅在我第一次关闭 emacs 后发生)重新启动,从那时起它假设是,这是我一直希望发生的情况)

I have this set in my init.el

(desktop-save-mode 1)

This works great, only I was wondering:

  • how can I change it to save the .emacs.desktop files into ~/.emacs.d instead of ~/

  • how can I stop it from asking me if I want to save (only occurs the first time I close emacs after a reboot, from then on it assumes yes, which is what I always want to happen)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

上课铃就是安魂曲 2024-10-15 09:28:18

我使用以下内容,这对我有用:

;; Automatically save and restore sessions
(setq desktop-dirname             "~/.emacs.d/desktop/"
      desktop-base-file-name      "emacs.desktop"
      desktop-base-lock-name      "lock"
      desktop-path                (list desktop-dirname)
      desktop-save                t
      desktop-files-not-to-save   "^$" ;reload tramp paths
      desktop-load-locked-desktop nil
      desktop-auto-save-timeout   30)
(desktop-save-mode 1)

嗯,我实际上设置了(desktop-save-mode 0),然后使用Mx my-desktop来启动:

(defun my-desktop ()
  "Load the desktop and enable autosaving"
  (interactive)
  (let ((desktop-load-locked-desktop "ask"))
    (desktop-read)
    (desktop-save-mode 1)))

但是这是因为我的会话经常超过 100 个文件,主要是通过 Tramp,所以我更喜欢将其加载为手动任务,而不是破坏桌面文件:)

我建议查看 Emacs Wiki:
http://www.emacswiki.org/emacs/DeskTop

对默认值有一些有用的增强功能。特别是,我建议添加一些在会话中自动保存桌面的方法,因为如果您的系统在 Emacs 运行了几天后崩溃并且您的桌面尚未保存,那么真的会很烦人在此期间。

从 Emacs 24.4 开始,默认情况下桌面文件会定期自动保存。请参阅 desktop-auto-save-timeout 变量(我也将其添加到上面的块中)。感谢 GDP2 和 Dexter Morgan 对此的评论。

I use the following, which works for me:

;; Automatically save and restore sessions
(setq desktop-dirname             "~/.emacs.d/desktop/"
      desktop-base-file-name      "emacs.desktop"
      desktop-base-lock-name      "lock"
      desktop-path                (list desktop-dirname)
      desktop-save                t
      desktop-files-not-to-save   "^$" ;reload tramp paths
      desktop-load-locked-desktop nil
      desktop-auto-save-timeout   30)
(desktop-save-mode 1)

Well, I actually set (desktop-save-mode 0) and then use M-x my-desktop to kick things off:

(defun my-desktop ()
  "Load the desktop and enable autosaving"
  (interactive)
  (let ((desktop-load-locked-desktop "ask"))
    (desktop-read)
    (desktop-save-mode 1)))

But that's because my session is frequently in excess of 100 files, mostly via tramp, and so I prefer to make loading it a manual task, and not clobber the desktop file otherwise :)

I recommend checking out the Emacs Wiki:
http://www.emacswiki.org/emacs/DeskTop

There are some useful enhancements to the default functionality. In particular, I recommend adding some method of auto-saving your desktop mid-session, as it's really annoying if your system crashes when Emacs has been running for several days, and your desktop hasn't been saved in the interim.

Since Emacs 24.4 the desktop file is auto-saved periodically by default. See the desktop-auto-save-timeout variable (which I've also added to the block above). Thanks to GDP2 and Dexter Morgan for their comments on this.

§对你不离不弃 2024-10-15 09:28:18

如何更改它以保存
.emacs.desktop 文件放入 ~/.emacs.d
而不是~/

自定义 desktop-dirname 变量。

我怎样才能阻止它询问我是否
想要保存

自定义desktop-save变量。

how can I change it to save the
.emacs.desktop files into ~/.emacs.d
instead of ~/

Customize desktop-dirname variable.

how can I stop it from asking me if I
want to save

Customize desktop-save variable.

虫児飞 2024-10-15 09:28:18

想分享我的会议是如何组织的。

要求:

  1. 从终端发送文件到自定义 emacs 会话
  2. 从终端恢复会话
  3. 保存会话

解决方案:

  1. 安装包(插件)workgroups2 -> https://github.com/pashinin/workgroups2

  2. 将以下 lisp 代码添加到您的 ~/. emacs.d/init.el 或 ~/.emacs:

->

(setq server-socket-dir "~/.emacs-local/server")

(defun nk-server-start (custom-server)
    ; (nk-server-start "abe")
    (setq server-name custom-server)
    (server-start) ; run emacs server
    (setq wg-session-file (concat "~/.emacs-local/sessions/" custom-server))
    ; (setq wg-session-file "~/.emacs-local/sessions/foo")
    (workgroups-mode 1)
    (wg-switch-to-workgroup custom-server)
    )
; Run file in specific server (foo)
    ; emacsclient -n callback.sh -s ~/.emacs-local/server/foo

; Show server name in title bar
(setq frame-title-format '("" "%b @ " server-name))
    ; https://www.emacswiki.org/emacs/FrameTitle

; ;; What to do on Emacs exit / workgroups-mode exit?
(setq wg-emacs-exit-save-behavior           'save)      ; Options: 'save 'ask nil
(setq wg-workgroups-mode-exit-save-behavior 'save)      ; Options: 'save 'ask nil

函数 nk-server-start 在 emacs 启动时被调用。
它有一个参数 - 会话名称。

我们可以通过从终端运行以下命令来启动 emacs-session foo

setsid emacs --eval '(nk-server-start "foo")' &

如果我们想从终端打开会话 foo 中的文件,我们需要运行:

setsid emacsclient -n -s ~/.emacs-local/server/foo file.txt >> /dev/null &

当我们关闭会话时,所有缓冲区、设置等保存在文件 ~/.emacs-local/sessions/foo

当我们运行命令 setsid emacs --eval '(nk-server-start "foo") ' & 下次,所有缓冲区都将被恢复

,因为命令很大而且我很懒:)我制作了一些脚本并将它们添加到我的 $PATH 中以缓解这个问题:

< code>em_start_foo.sh - 运行会话,仅使用一次来启动会话

#!/bin/bash

setsid emacs --eval '(nk-server-start "foo")' &

em_foo.sh - 将文件添加到会话

#!/bin/bash

setsid emacsclient -n -s ~/.emacs-local/server/foo "$@" >> /dev/null &

现在我们只需从终端运行:

$ em_start_foo.sh                 # start foo session
$ em_foo.sh file_1.txt            # open file_1.txt in foo session
$ em_foo.sh file_2.txt file_3.txt # open file_2.txt and file_3.txt in foo session

当然多个会话可以并行运行。

假设我们还创建了脚本 em_start_foo_2.shem_start_foo_2.shem_start_foo_3.shem_start_foo_3.sh (当然是在 $PATH 的某个地方)

然后我们可以做这样的事情:

$ em_start_foo.sh          # start foo session
$ em_start_foo_2.sh        # start foo_2 session in separate emacs
$ em_foo.sh file_1.txt     # open file_1.txt in foo session
$ em_foo_2.sh a.txt b.txt  # open a.txt and b.txt in foo_2 session

$ em_start_foo_3.sh        # start foo_3 session
$ em_foo_3.sh tmp.txt      # open tmp.txt in foo_3 session

##### Close emacs foo_2 from gui - session is automatically saved ###

$ em_start_foo_2.sh        # start foo_2 session with all buffers restored

Package workgroups2 真的很棒!

我的带有会话选项的 emacs 初始化文件位于: https:// github.com/nexayq/dot_files/blob/master/emacs/dot_emacs_d/init.el

Wanted to share how my sessions are organized.

Requirements:

  1. Send file from terminal to custom emacs session
  2. Restore session from terminal
  3. Save session

Solution:

  1. Install package(plugin) workgroups2 -> https://github.com/pashinin/workgroups2

  2. Add following lisp code to your ~/.emacs.d/init.el or ~/.emacs:

->

(setq server-socket-dir "~/.emacs-local/server")

(defun nk-server-start (custom-server)
    ; (nk-server-start "abe")
    (setq server-name custom-server)
    (server-start) ; run emacs server
    (setq wg-session-file (concat "~/.emacs-local/sessions/" custom-server))
    ; (setq wg-session-file "~/.emacs-local/sessions/foo")
    (workgroups-mode 1)
    (wg-switch-to-workgroup custom-server)
    )
; Run file in specific server (foo)
    ; emacsclient -n callback.sh -s ~/.emacs-local/server/foo

; Show server name in title bar
(setq frame-title-format '("" "%b @ " server-name))
    ; https://www.emacswiki.org/emacs/FrameTitle

; ;; What to do on Emacs exit / workgroups-mode exit?
(setq wg-emacs-exit-save-behavior           'save)      ; Options: 'save 'ask nil
(setq wg-workgroups-mode-exit-save-behavior 'save)      ; Options: 'save 'ask nil

Function nk-server-start is called when emacs is started.
It has one argument - sesssion name.

We can start emacs-session foo by running following command from terminal:

setsid emacs --eval '(nk-server-start "foo")' &

If we want to open file in session foo from terminal we need to run:

setsid emacsclient -n -s ~/.emacs-local/server/foo file.txt >> /dev/null &

When we close session, all buffers,settings, etc. are saved in file ~/.emacs-local/sessions/foo

When we run command setsid emacs --eval '(nk-server-start "foo")' & next time, all buffers will be restored

Because commands are large and I am lazy :) I made some scripts and added them to my $PATH in order to ease this:

em_start_foo.sh - Run session, used only once to start session

#!/bin/bash

setsid emacs --eval '(nk-server-start "foo")' &

em_foo.sh - Add files to session

#!/bin/bash

setsid emacsclient -n -s ~/.emacs-local/server/foo "$@" >> /dev/null &

Now we just run from terminal:

$ em_start_foo.sh                 # start foo session
$ em_foo.sh file_1.txt            # open file_1.txt in foo session
$ em_foo.sh file_2.txt file_3.txt # open file_2.txt and file_3.txt in foo session

Multiple sessions can be run in parallel of course.

Let's say we created also scripts em_start_foo_2.sh, em_start_foo_2.sh, em_start_foo_3.sh, em_start_foo_3.sh (somewhere in $PATH of course)

Then we can do something like this:

$ em_start_foo.sh          # start foo session
$ em_start_foo_2.sh        # start foo_2 session in separate emacs
$ em_foo.sh file_1.txt     # open file_1.txt in foo session
$ em_foo_2.sh a.txt b.txt  # open a.txt and b.txt in foo_2 session

$ em_start_foo_3.sh        # start foo_3 session
$ em_foo_3.sh tmp.txt      # open tmp.txt in foo_3 session

##### Close emacs foo_2 from gui - session is automatically saved ###

$ em_start_foo_2.sh        # start foo_2 session with all buffers restored

Package workgroups2 is really great!

My emacs init file with session options is available at: https://github.com/nexayq/dot_files/blob/master/emacs/dot_emacs_d/init.el

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文