From d4d08aec0b0669e111bef2613775020f24ab9562 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sun, 6 Nov 2022 12:05:45 -0800 Subject: [PATCH 2/2] [IDEA] Take advantage of new 'server-mode-map' to handle remapping 'C-x C-c' --- doc/emacs/entering.texi | 6 +++--- doc/lispref/os.texi | 20 ++++++++++---------- lisp/files.el | 16 +--------------- lisp/help.el | 2 +- lisp/menu-bar.el | 2 +- lisp/server.el | 20 +++++++++++++++++--- lisp/startup.el | 2 +- lisp/tutorial.el | 2 +- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/doc/emacs/entering.texi b/doc/emacs/entering.texi index 6069da0380..76e5bfca0f 100644 --- a/doc/emacs/entering.texi +++ b/doc/emacs/entering.texi @@ -98,16 +98,16 @@ Exiting @table @kbd @item C-x C-c -Kill Emacs (@code{save-buffers-kill-terminal}). +Kill Emacs (@code{save-buffers-kill-emacs}). @item C-z On a text terminal, suspend Emacs; on a graphical display, iconify (or ``minimize'') the selected frame (@code{suspend-frame}). @end table @kindex C-x C-c -@findex save-buffers-kill-terminal +@findex save-buffers-kill-emacs @dfn{Killing} Emacs means terminating the Emacs program. To do -this, type @kbd{C-x C-c} (@code{save-buffers-kill-terminal}). A +this, type @kbd{C-x C-c} (@code{save-buffers-kill-emacs}). A two-character key sequence is used to make it harder to type by accident. If there are any modified file-visiting buffers when you type @kbd{C-x C-c}, Emacs first offers to save these buffers. If you diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index 3e16ac0eb4..fcad449e0c 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi @@ -725,12 +725,12 @@ Killing Emacs @cindex SIGINT @cindex operating system signal The @code{kill-emacs} function is normally called via the -higher-level command @kbd{C-x C-c} -(@code{save-buffers-kill-terminal}). @xref{Exiting,,, emacs, The GNU -Emacs Manual}. It is also called automatically if Emacs receives a -@code{SIGTERM} or @code{SIGHUP} operating system signal (e.g., when the -controlling terminal is disconnected), or if it receives a -@code{SIGINT} signal while running in batch mode (@pxref{Batch Mode}). +higher-level command @kbd{C-x C-c} (@code{save-buffers-kill-emacs}). +@xref{Exiting,,, emacs, The GNU Emacs Manual}. It is also called +automatically if Emacs receives a @code{SIGTERM} or @code{SIGHUP} +operating system signal (e.g., when the controlling terminal is +disconnected), or if it receives a @code{SIGINT} signal while running +in batch mode (@pxref{Batch Mode}). @defvar kill-emacs-hook This normal hook is run by @code{kill-emacs}, before it kills Emacs. @@ -745,12 +745,12 @@ Killing Emacs When Emacs is killed, all the information in the Emacs process, aside from files that have been saved, is lost. Because killing Emacs inadvertently can lose a lot of work, the -@code{save-buffers-kill-terminal} command queries for confirmation if -you have buffers that need saving or subprocesses that are running. -It also runs the abnormal hook @code{kill-emacs-query-functions}: +@code{save-buffers-kill-emacs} command queries for confirmation if you +have buffers that need saving or subprocesses that are running. It +also runs the abnormal hook @code{kill-emacs-query-functions}: @defopt kill-emacs-query-functions -When @code{save-buffers-kill-terminal} is killing Emacs, it calls the +When @code{save-buffers-kill-emacs} is killing Emacs, it calls the functions in this hook, after asking the standard questions and before calling @code{kill-emacs}. The functions are called in order of appearance, with no arguments. Each function can ask for additional diff --git a/lisp/files.el b/lisp/files.el index a282532258..9f88a3e646 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -8072,20 +8072,6 @@ save-buffers-kill-emacs (funcall confirm "Really exit Emacs? ")) (kill-emacs nil restart)))) -(defun save-buffers-kill-terminal (&optional arg) - "Offer to save each buffer, then kill the current connection. -If the current frame has no client, kill Emacs itself using -`save-buffers-kill-emacs'. - -With prefix ARG, silently save all file-visiting buffers, then kill. - -If emacsclient was started with a list of file names to edit, then -only these files will be asked to be saved." - (interactive "P") - (if (frame-parameter nil 'client) - (server-save-buffers-kill-terminal arg) - (save-buffers-kill-emacs arg))) - (defun restart-emacs () "Kill the current Emacs process and start a new one. This goes through the same shutdown procedure as @@ -8700,7 +8686,7 @@ ctl-x-map (define-key ctl-x-map "i" 'insert-file) (define-key esc-map "~" 'not-modified) (define-key ctl-x-map "\C-d" 'list-directory) -(define-key ctl-x-map "\C-c" 'save-buffers-kill-terminal) +(define-key ctl-x-map "\C-c" 'save-buffers-kill-emacs) (define-key ctl-x-map "\C-q" 'read-only-mode) (define-key ctl-x-4-map "f" 'find-file-other-window) diff --git a/lisp/help.el b/lisp/help.el index b25a8ce299..41f654965d 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -130,7 +130,7 @@ help-button-cache (defvar help-quick-sections '(("File" - (save-buffers-kill-terminal . "exit") + (save-buffers-kill-emacs . "exit") (find-file . "find") (write-file . "write") (save-buffer . "save") diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 849e0f7723..4e746c3483 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -84,7 +84,7 @@ menu-bar-file-menu ;; The "File" menu items (bindings--define-key menu [exit-emacs] - '(menu-item "Quit" save-buffers-kill-terminal + '(menu-item "Quit" save-buffers-kill-emacs :help "Save unsaved buffers, then exit")) (bindings--define-key menu [separator-exit] diff --git a/lisp/server.el b/lisp/server.el index 553890ce29..af79fa046f 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -799,9 +799,8 @@ server-running-p t) (file-error nil))) -;; This keymap is empty, but allows users to define keybindings to use -;; when `server-mode' is active. -(defvar-keymap server-mode-map) +(defvar-keymap server-mode-map + " " #'save-buffers-kill-terminal) ;;;###autoload (define-minor-mode server-mode @@ -1773,6 +1772,21 @@ server-save-buffers-kill-terminal (server-delete-client proc))) (t (error "Invalid client frame")))))) +;;;###autoload +(defun save-buffers-kill-terminal (&optional arg) + "Offer to save each buffer, then kill the current connection. +If the current frame has no client, kill Emacs itself using +`save-buffers-kill-emacs'. + +With prefix ARG, silently save all file-visiting buffers, then kill. + +If emacsclient was started with a list of file names to edit, then +only these files will be asked to be saved." + (interactive "P") + (if (frame-parameter nil 'client) + (server-save-buffers-kill-terminal arg) + (save-buffers-kill-emacs arg))) + (defun server-stop-automatically--handle-delete-frame (frame) "Handle deletion of FRAME when `server-stop-automatically' is used." (when server-stop-automatically diff --git a/lisp/startup.el b/lisp/startup.el index 70267fc857..2d38f99850 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -2308,7 +2308,7 @@ normal-no-mouse-startup-screen 'action (lambda (_button) (view-order-manuals)) 'follow-link t) (insert (substitute-command-keys - "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-terminal]"))) + "\t \\[view-order-manuals]\tExit Emacs\t \\[save-buffers-kill-emacs]"))) ;; Say how to use the menu bar with the keyboard. (insert "\n") diff --git a/lisp/tutorial.el b/lisp/tutorial.el index 2c787ae559..ba3a5505c2 100644 --- a/lisp/tutorial.el +++ b/lisp/tutorial.el @@ -209,7 +209,7 @@ tutorial--default-keys `((ESC-prefix [27]) (Control-X-prefix [?\C-x]) (mode-specific-command-prefix [?\C-c]) - (save-buffers-kill-terminal [?\C-x ?\C-c]) + (save-buffers-kill-emacs [?\C-x ?\C-c]) ;; * SUMMARY (scroll-up-command [?\C-v]) -- 2.25.1