2011-04-20 19:31:06 -03:00
|
|
|
;;; shell.el --- specialized comint.el for running the shell -*- lexical-binding: t -*-
|
1994-04-14 22:49:23 +00:00
|
|
|
|
2025-01-01 07:39:17 +00:00
|
|
|
;; Copyright (C) 1988, 1993-1997, 2000-2025 Free Software Foundation,
|
2015-01-01 14:26:41 -08:00
|
|
|
;; Inc.
|
1992-07-22 03:58:44 +00:00
|
|
|
|
2001-07-14 11:21:08 +00:00
|
|
|
;; Author: Olin Shivers <shivers@cs.cmu.edu>
|
1999-08-16 04:04:27 +00:00
|
|
|
;; Simon Marshall <simon@gnu.org>
|
2019-05-25 13:43:06 -07:00
|
|
|
;; Maintainer: emacs-devel@gnu.org
|
1992-07-17 20:24:00 +00:00
|
|
|
;; Keywords: processes
|
1992-07-15 21:31:44 +00:00
|
|
|
|
1994-04-14 22:49:23 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
1992-05-30 21:11:25 +00:00
|
|
|
|
2008-05-06 08:06:51 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1994-04-14 22:49:23 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:06:51 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
1992-05-30 21:11:25 +00:00
|
|
|
|
1994-04-14 22:49:23 +00:00
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
1992-05-30 21:11:25 +00:00
|
|
|
|
1994-04-14 22:49:23 +00:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1992-07-15 21:31:44 +00:00
|
|
|
;;; Commentary:
|
|
|
|
|
2002-07-03 12:01:24 +00:00
|
|
|
;; This file defines a shell-in-a-buffer package (shell mode) built on
|
2021-02-05 02:27:57 +01:00
|
|
|
;; top of comint mode.
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
;; Since this mode is built on top of the general command-interpreter-in-
|
2001-01-28 03:43:35 +00:00
|
|
|
;; a-buffer mode (comint mode), it shares a common base functionality,
|
1996-01-14 07:34:30 +00:00
|
|
|
;; and a common set of bindings, with all modes derived from comint mode.
|
|
|
|
;; This makes these modes easier to use.
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
;; For documentation on the functionality provided by comint mode, and
|
2011-12-11 21:32:49 -08:00
|
|
|
;; the hooks available for customizing it, see the file comint.el.
|
1996-01-14 07:34:30 +00:00
|
|
|
;; For further information on shell mode, see the comments below.
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2024-05-27 10:11:15 +02:00
|
|
|
;; Needs fixing:
|
2001-01-28 03:43:35 +00:00
|
|
|
;; When sending text from a source file to a subprocess, the process-mark can
|
1996-01-14 07:34:30 +00:00
|
|
|
;; move off the window, so you can lose sight of the process interactions.
|
|
|
|
;; Maybe I should ensure the process mark is in the window when I send
|
|
|
|
;; text to the process? Switch selectable?
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1991-05-08 07:47:45 +00:00
|
|
|
;; YOUR .EMACS FILE
|
|
|
|
;;=============================================================================
|
2012-09-17 13:41:04 +08:00
|
|
|
;; Some suggestions for your init file.
|
1991-05-08 07:47:45 +00:00
|
|
|
;;
|
1995-02-21 13:07:23 +00:00
|
|
|
;; ;; Define M-# to run some strange command:
|
Recommend using 'keymap-set' in Commentaries
* lisp/calendar/timeclock.el, lisp/comint.el, lisp/ehelp.el:
* lisp/gnus/gnus-bookmark.el, lisp/gnus/smiley.el, lisp/ido.el:
* lisp/isearchb.el, lisp/mail/mailabbrev.el, lisp/net/ange-ftp.el:
* lisp/net/goto-addr.el, lisp/play/fortune.el, lisp/saveplace.el:
* lisp/shell.el, lisp/term.el, lisp/textmodes/makeinfo.el:
* lisp/textmodes/refer.el, lisp/textmodes/remember.el:
* lisp/textmodes/table.el, lisp/woman.el: Recommend using
'keymap-set' instead of 'define-key' in Commentaries.
2025-03-15 01:01:16 +01:00
|
|
|
;; (with-eval-after-load 'shell
|
|
|
|
;; (keymap-set shell-mode-map "M-#" 'shells-dynamic-spell))
|
2001-01-28 03:43:35 +00:00
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
;; Brief Command Documentation:
|
|
|
|
;;============================================================================
|
|
|
|
;; Comint Mode Commands: (common to shell and all comint-derived modes)
|
|
|
|
;;
|
1998-06-28 22:43:25 +00:00
|
|
|
;; m-p comint-previous-input Cycle backwards in input history
|
|
|
|
;; m-n comint-next-input Cycle forwards
|
1996-01-14 07:34:30 +00:00
|
|
|
;; m-r comint-previous-matching-input Previous input matching a regexp
|
|
|
|
;; m-s comint-next-matching-input Next input that matches
|
1998-06-28 22:43:25 +00:00
|
|
|
;; m-c-l comint-show-output Show last batch of process output
|
1996-01-14 07:34:30 +00:00
|
|
|
;; return comint-send-input
|
1998-06-28 22:43:25 +00:00
|
|
|
;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff.
|
1996-01-14 07:34:30 +00:00
|
|
|
;; c-c c-a comint-bol Beginning of line; skip prompt
|
1998-06-28 22:43:25 +00:00
|
|
|
;; c-c c-u comint-kill-input ^u
|
|
|
|
;; c-c c-w backward-kill-word ^w
|
|
|
|
;; c-c c-c comint-interrupt-subjob ^c
|
|
|
|
;; c-c c-z comint-stop-subjob ^z
|
|
|
|
;; c-c c-\ comint-quit-subjob ^\
|
Remove some functions, variables and aliases obsolete since at least 21.1.
* doc/misc/misc.texi (Shell Mode): Remove reference to old function name.
* src/character.c (Fchar_bytes): Remove obsolete function.
(syms_of_character): Remove Schar_bytes.
* lisp/subr.el (char-bytes): Remove obsolete function.
* lisp/emacs-lisp/checkdoc.el (checkdoc-minor-keymap): Remove obsolete alias.
* lisp/isearch.el (isearch-return-char): Remove obsolete function.
* lisp/mouse.el: No longer provide mldrag.
(mldrag-drag-mode-line, mldrag-drag-vertical-line):
Remove obsolete aliases.
* lisp/comint.el (comint-kill-output): Remove obsolete alias.
* lisp/shell.el: Comment fix.
* lisp/composite.el (decompose-composite-char): Remove obsolete function.
* lisp/ps-def.el (decompose-composite-char): Remove unused function.
* lisp/iswitchb.el (iswitchb-default-keybindings): Remove obsolete function.
* lisp/outline.el (outline-visible): Remove obsolete function.
* lisp/term/pc-win.el (x-frob-font-slant, x-frob-font-weight):
* lisp/faces.el (internal-find-face, internal-get-face)
(frame-update-faces, frame-update-face-colors)
(x-frob-font-weight, x-frob-font-slant)
(internal-frob-font-weight, internal-frob-font-slant)
(x-make-font-bold, x-make-font-demibold, x-make-font-unbold)
(x-make-font-italic, x-make-font-oblique, x-make-font-unitalic)
(x-make-font-bold-italic): Remove functions and aliases, obsolete
since Emacs 21.1.
* lisp/emulation/viper-util.el (viper-get-face):
* lisp/obsolete/lucid.el (find-face, get-face): Use facep.
* lisp/vc/ediff-init.el (ediff-valid-color-p, ediff-get-face):
Remove unused functions.
* lisp/vc/ediff-util.el (ediff-submit-report): Doc fix.
* etc/NEWS: Mention above changes.
2010-10-01 19:46:13 -07:00
|
|
|
;; c-c c-o comint-delete-output Delete last batch of process output
|
1998-06-28 22:43:25 +00:00
|
|
|
;; c-c c-r comint-show-output Show last batch of process output
|
1999-05-17 06:14:44 +00:00
|
|
|
;; c-c c-l comint-dynamic-list-input-ring List input history
|
2022-12-01 16:36:09 +01:00
|
|
|
;; comint-send-invisible Read line without echo & send to proc
|
1998-06-28 22:43:25 +00:00
|
|
|
;; comint-continue-subjob Useful if you accidentally suspend
|
1996-01-14 07:34:30 +00:00
|
|
|
;; top-level job
|
|
|
|
;; comint-mode-hook is the comint mode hook.
|
|
|
|
|
|
|
|
;; Shell Mode Commands:
|
|
|
|
;; shell Fires up the shell process
|
2011-04-20 19:31:06 -03:00
|
|
|
;; tab completion-at-point Complete filename/command/history
|
1996-01-14 07:34:30 +00:00
|
|
|
;; m-? comint-dynamic-list-filename-completions
|
|
|
|
;; List completions in help buffer
|
2015-06-23 09:19:36 +08:00
|
|
|
;; c-c c-f shell-forward-command Forward a shell command
|
|
|
|
;; c-c c-b shell-backward-command Backward a shell command
|
1998-06-28 22:43:25 +00:00
|
|
|
;; dirs Resync the buffer's dir stack
|
2007-10-27 22:15:27 +00:00
|
|
|
;; shell-dirtrack-mode Turn dir tracking on/off
|
1996-01-14 07:34:30 +00:00
|
|
|
;; comint-strip-ctrl-m Remove trailing ^Ms from output
|
|
|
|
;;
|
|
|
|
;; The shell mode hook is shell-mode-hook
|
2011-11-19 18:29:42 -08:00
|
|
|
;; comint-prompt-regexp is initialized to shell-prompt-pattern, for backwards
|
1996-01-14 07:34:30 +00:00
|
|
|
;; compatibility.
|
1991-05-08 07:47:45 +00:00
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
;; Read the rest of this file for more information.
|
2001-01-28 03:43:35 +00:00
|
|
|
|
1992-07-15 21:31:44 +00:00
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'comint)
|
2011-06-04 09:31:34 -03:00
|
|
|
(require 'pcomplete)
|
2019-03-09 16:44:24 +01:00
|
|
|
(eval-when-compile (require 'files-x)) ;with-connection-local-variables
|
2022-04-11 12:12:41 +02:00
|
|
|
(require 'subr-x)
|
2022-09-09 20:10:01 +02:00
|
|
|
(eval-when-compile (require 'cl-lib))
|
1992-07-15 21:31:44 +00:00
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
;;; Customization and Buffer Variables
|
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defgroup shell nil
|
2005-07-04 02:28:54 +00:00
|
|
|
"Running shell from within Emacs buffers."
|
1997-04-13 02:39:56 +00:00
|
|
|
:group 'processes
|
|
|
|
:group 'unix)
|
|
|
|
|
|
|
|
(defgroup shell-directories nil
|
2005-07-04 02:28:54 +00:00
|
|
|
"Directory support in shell mode."
|
1997-04-13 02:39:56 +00:00
|
|
|
:group 'shell)
|
|
|
|
|
1992-05-30 21:11:25 +00:00
|
|
|
;;;###autoload
|
Delete remaining calls to purecopy
* lisp/button.el (default-button):
* lisp/calendar/holidays.el (holiday-solar-holidays)
(holiday-bahai-holidays, holiday-islamic-holidays)
(holiday-christian-holidays, holiday-hebrew-holidays)
(holiday-oriental-holidays, holiday-general-holidays):
* lisp/comint.el (comint-file-name-prefix):
* lisp/composite.el (unicode-category-table):
* lisp/cus-face.el (custom-declare-face):
* lisp/custom.el (custom-add-load, custom-add-package-version)
(custom-add-version, custom-add-link, custom-declare-group)
(custom-declare-variable):
* lisp/dired.el (dired-listing-switches):
* lisp/epa-hook.el (epa-file-name-regexp):
* lisp/faces.el (x-font-regexp, x-font-regexp-head)
(x-font-regexp-slant, x-font-regexp-weight, )
(set-face-attribute, set-face-documentation, face-x-resources)
(face-font-registry-alternatives, face-font-family-alternatives)
(term-file-prefix):
* lisp/find-file.el (ff-special-constructs):
* lisp/format.el (format-alist):
* lisp/help.el (help-for-help):
* lisp/image-file.el (image-file-name-extensions):
* lisp/info.el:
* lisp/isearch.el (isearch-help-for-help-internal)
(search-whitespace-regexp):
* lisp/jka-cmpr-hook.el (jka-compr-load-suffixes)
(jka-compr-mode-alist-additions)
(jka-compr-compression-info-list, jka-compr-build-file-regexp):
* lisp/language/ethiopic.el (font-ccl-encoder-alist):
* lisp/language/korea-util.el (default-korean-keyboard):
* lisp/language/tibetan.el (tibetan-precomposition-rule-regexp)
(tibetan-precomposed-regexp):
* lisp/locate.el (locate-ls-subdir-switches):
* lisp/lpr.el (lpr-command):
* lisp/mail/rmail.el (rmail-secondary-file-regexp)
(rmail-secondary-file-directory, rmail-highlighted-headers)
(rmail-ignored-headers, rmail-spool-directory, rmail-file-name):
* lisp/mail/sendmail.el (mail-default-directory)
(mail-signature-file, mail-citation-prefix-regexp)
(mail-personal-alias-file, mail-header-separator):
* lisp/menu-bar.el (yank-menu):
* lisp/net/eudc.el (eudc-tools-menu):
* lisp/newcomment.el (comment-padding, comment-end):
* lisp/obsolete/autoload.el (autoload-generate-file-autoloads):
* lisp/progmodes/hideshow.el (hs-special-modes-alist):
* lisp/ps-print.el (ps-page-dimensions-database):
* lisp/rfn-eshadow.el (file-name-shadow-tty-properties):
* lisp/shell.el (shell-dumb-shell-regexp):
* lisp/simple.el (overwrite-mode-binary, overwrite-mode-textual)
(mark-inactive, shell-command-switch)
(next-error-overlay-arrow-position):
* lisp/subr.el (package--builtin-versions, eval-after-load):
* lisp/tab-bar.el ([tab-bar]):
* lisp/term/pgtk-win.el (x-gtk-stock-map):
* lisp/term/x-win.el (x-gtk-stock-map):
* lisp/tool-bar.el ([tool-bar]):
* lisp/widget.el (define-widget): Remove calls to purecopy.
2024-12-09 21:26:25 +01:00
|
|
|
(defcustom shell-dumb-shell-regexp "cmd\\(proxy\\)?\\.exe"
|
2001-01-27 12:43:56 +00:00
|
|
|
"Regexp to match shells that don't save their command history, and
|
|
|
|
don't handle the backslash as a quote character. For shells that
|
|
|
|
match this regexp, Emacs will write out the command history when the
|
|
|
|
shell finishes, and won't remove backslashes when it unquotes shell
|
|
|
|
arguments."
|
2000-09-14 21:15:44 +00:00
|
|
|
:type 'regexp
|
|
|
|
:group 'shell)
|
|
|
|
|
1998-11-22 15:33:21 +00:00
|
|
|
(defcustom shell-prompt-pattern "^[^#$%>\n]*[#$%>] *"
|
1991-05-08 07:47:45 +00:00
|
|
|
"Regexp to match prompts in the inferior shell.
|
1993-07-18 06:20:47 +00:00
|
|
|
Defaults to \"^[^#$%>\\n]*[#$%>] *\", which works pretty well.
|
2005-06-16 16:10:43 +00:00
|
|
|
This variable is used to initialize `comint-prompt-regexp' in the
|
1991-05-08 07:47:45 +00:00
|
|
|
shell buffer.
|
|
|
|
|
2005-04-26 23:16:20 +00:00
|
|
|
If `comint-use-prompt-regexp' is nil, then this variable is only used
|
|
|
|
to determine paragraph boundaries. See Info node `Shell Prompts' for
|
|
|
|
how Shell mode treats paragraphs.
|
2000-08-07 14:51:48 +00:00
|
|
|
|
1993-07-18 06:20:47 +00:00
|
|
|
The pattern should probably not match more than one line. If it does,
|
1996-02-03 13:38:32 +00:00
|
|
|
Shell mode may become confused trying to distinguish prompt from input
|
2012-09-17 13:01:10 +08:00
|
|
|
on lines which don't start with a prompt."
|
1998-11-22 15:33:21 +00:00
|
|
|
:type 'regexp
|
|
|
|
:group 'shell)
|
1991-05-08 07:47:45 +00:00
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-completion-fignore nil
|
2006-05-17 21:57:25 +00:00
|
|
|
"List of suffixes to be disregarded during file/command completion.
|
1994-03-08 17:43:07 +00:00
|
|
|
This variable is used to initialize `comint-completion-fignore' in the shell
|
|
|
|
buffer. The default is nil, for compatibility with most shells.
|
2012-09-17 13:01:10 +08:00
|
|
|
Some people like (\"~\" \"#\" \"%\")."
|
1997-04-13 02:39:56 +00:00
|
|
|
:type '(repeat (string :tag "Suffix"))
|
|
|
|
:group 'shell)
|
1994-03-08 17:43:07 +00:00
|
|
|
|
2012-02-15 00:00:23 -08:00
|
|
|
(defcustom shell-delimiter-argument-list '(?\| ?& ?< ?> ?\( ?\) ?\;)
|
2005-06-16 16:10:43 +00:00
|
|
|
"List of characters to recognize as separate arguments.
|
1994-03-02 22:02:56 +00:00
|
|
|
This variable is used to initialize `comint-delimiter-argument-list' in the
|
2011-02-16 21:02:02 -08:00
|
|
|
shell buffer. The value may depend on the operating system or shell."
|
|
|
|
:type '(choice (const nil)
|
|
|
|
(repeat :tag "List of characters" character))
|
|
|
|
:group 'shell)
|
1996-07-12 07:34:20 +00:00
|
|
|
|
2012-09-17 13:01:10 +08:00
|
|
|
(defcustom shell-file-name-chars
|
2003-01-31 15:24:20 +00:00
|
|
|
(if (memq system-type '(ms-dos windows-nt cygwin))
|
1998-04-17 05:25:04 +00:00
|
|
|
"~/A-Za-z0-9_^$!#%&{}@`'.,:()-"
|
2003-12-29 19:13:28 +00:00
|
|
|
"[]~/A-Za-z0-9+@:_.$#%,={}-")
|
1996-08-01 22:35:03 +00:00
|
|
|
"String of characters valid in a file name.
|
|
|
|
This variable is used to initialize `comint-file-name-chars' in the
|
2012-09-17 13:01:10 +08:00
|
|
|
shell buffer. The value may depend on the operating system or shell."
|
|
|
|
:type 'string
|
|
|
|
:group 'shell)
|
1993-10-22 02:53:24 +00:00
|
|
|
|
2012-09-17 13:01:10 +08:00
|
|
|
(defcustom shell-file-name-quote-list
|
1996-07-12 07:34:20 +00:00
|
|
|
(if (memq system-type '(ms-dos windows-nt))
|
|
|
|
nil
|
2008-08-27 17:04:23 +00:00
|
|
|
(append shell-delimiter-argument-list '(?\s ?$ ?\* ?\! ?\" ?\' ?\` ?\# ?\\)))
|
1995-04-03 13:01:15 +00:00
|
|
|
"List of characters to quote when in a file name.
|
|
|
|
This variable is used to initialize `comint-file-name-quote-list' in the
|
2012-09-17 13:01:10 +08:00
|
|
|
shell buffer. The value may depend on the operating system or shell."
|
|
|
|
:type '(repeat character)
|
|
|
|
:group 'shell)
|
1995-04-03 13:01:15 +00:00
|
|
|
|
2012-09-17 13:01:10 +08:00
|
|
|
(defcustom shell-dynamic-complete-functions
|
2011-04-20 19:31:06 -03:00
|
|
|
'(comint-c-a-p-replace-by-expanded-history
|
|
|
|
shell-environment-variable-completion
|
|
|
|
shell-command-completion
|
|
|
|
shell-c-a-p-replace-by-expanded-directory
|
2020-07-18 11:17:31 +03:00
|
|
|
pcomplete-completions-at-point
|
2011-04-20 19:31:06 -03:00
|
|
|
shell-filename-completion
|
2020-07-18 11:17:31 +03:00
|
|
|
comint-filename-completion)
|
1994-03-03 23:37:27 +00:00
|
|
|
"List of functions called to perform completion.
|
2005-06-16 16:10:43 +00:00
|
|
|
This variable is used to initialize `comint-dynamic-complete-functions' in the
|
2012-09-17 13:01:10 +08:00
|
|
|
shell buffer."
|
|
|
|
:type '(repeat function)
|
|
|
|
:group 'shell)
|
1994-03-03 23:37:27 +00:00
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-command-regexp "[^;&|\n]+"
|
2006-05-17 21:57:25 +00:00
|
|
|
"Regexp to match a single command within a pipeline.
|
1997-04-13 02:39:56 +00:00
|
|
|
This is used for directory tracking and does not do a perfect job."
|
|
|
|
:type 'regexp
|
|
|
|
:group 'shell)
|
1993-10-22 02:53:24 +00:00
|
|
|
|
2003-06-12 22:20:49 +00:00
|
|
|
(defcustom shell-command-separator-regexp "[;&|\n \t]*"
|
2006-05-17 21:57:25 +00:00
|
|
|
"Regexp to match a single command within a pipeline.
|
2003-06-12 22:20:49 +00:00
|
|
|
This is used for directory tracking and does not do a perfect job."
|
|
|
|
:type 'regexp
|
|
|
|
:group 'shell)
|
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-completion-execonly t
|
2006-05-17 21:57:25 +00:00
|
|
|
"If non-nil, use executable files only for completion candidates.
|
1993-11-08 23:40:37 +00:00
|
|
|
This mirrors the optional behavior of tcsh.
|
1993-10-22 02:53:24 +00:00
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
Detecting executability of files may slow command completion considerably."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'shell)
|
1993-10-22 02:53:24 +00:00
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-popd-regexp "popd"
|
2006-05-17 21:57:25 +00:00
|
|
|
"Regexp to match subshell commands equivalent to popd."
|
1997-04-13 02:39:56 +00:00
|
|
|
:type 'regexp
|
|
|
|
:group 'shell-directories)
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-pushd-regexp "pushd"
|
2006-05-17 21:57:25 +00:00
|
|
|
"Regexp to match subshell commands equivalent to pushd."
|
1997-04-13 02:39:56 +00:00
|
|
|
:type 'regexp
|
|
|
|
:group 'shell-directories)
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-pushd-tohome nil
|
2006-05-17 21:57:25 +00:00
|
|
|
"If non-nil, make pushd with no arg behave as \"pushd ~\" (like cd).
|
1997-04-13 02:39:56 +00:00
|
|
|
This mirrors the optional behavior of tcsh."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'shell-directories)
|
1993-10-22 02:53:24 +00:00
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-pushd-dextract nil
|
2006-05-17 21:57:25 +00:00
|
|
|
"If non-nil, make \"pushd +n\" pop the nth dir to the stack top.
|
1997-04-13 02:39:56 +00:00
|
|
|
This mirrors the optional behavior of tcsh."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'shell-directories)
|
1993-10-22 02:53:24 +00:00
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-pushd-dunique nil
|
2006-05-17 21:57:25 +00:00
|
|
|
"If non-nil, make pushd only add unique directories to the stack.
|
1997-04-13 02:39:56 +00:00
|
|
|
This mirrors the optional behavior of tcsh."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'shell-directories)
|
1993-10-22 02:53:24 +00:00
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-cd-regexp "cd"
|
2006-05-17 21:57:25 +00:00
|
|
|
"Regexp to match subshell commands equivalent to cd."
|
1997-04-13 02:39:56 +00:00
|
|
|
:type 'regexp
|
|
|
|
:group 'shell-directories)
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-chdrive-regexp
|
2001-01-28 03:43:35 +00:00
|
|
|
(if (memq system-type '(ms-dos windows-nt))
|
1996-06-09 20:31:51 +00:00
|
|
|
; NetWare allows the five chars between upper and lower alphabetics.
|
2020-02-17 18:26:47 +01:00
|
|
|
"[]a-zA-Z^_`[\\]:"
|
1996-06-09 20:31:51 +00:00
|
|
|
nil)
|
2006-05-17 21:57:25 +00:00
|
|
|
"If non-nil, is regexp used to track drive changes."
|
1997-09-09 02:56:56 +00:00
|
|
|
:type '(choice regexp
|
|
|
|
(const nil))
|
1997-04-13 02:39:56 +00:00
|
|
|
:group 'shell-directories)
|
1996-06-09 20:31:51 +00:00
|
|
|
|
1999-01-14 10:31:31 +00:00
|
|
|
(defcustom shell-dirtrack-verbose t
|
2006-05-17 21:57:25 +00:00
|
|
|
"If non-nil, show the directory stack following directory change.
|
2007-10-27 22:15:27 +00:00
|
|
|
This is effective only if directory tracking is enabled.
|
2007-10-30 06:39:00 +00:00
|
|
|
The `dirtrack' package provides an alternative implementation of this feature -
|
|
|
|
see the function `dirtrack-mode'."
|
1999-01-14 10:31:31 +00:00
|
|
|
:type 'boolean
|
|
|
|
:group 'shell-directories)
|
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom explicit-shell-file-name nil
|
2020-04-17 10:27:36 +01:00
|
|
|
"If non-nil, the file name to use for explicitly requested inferior shells.
|
|
|
|
When nil, such interactive shell sessions fall back to using the
|
|
|
|
shell specified in either the environment variable \"ESHELL\" or
|
|
|
|
`shell-file-name'."
|
|
|
|
:type '(choice (const :tag "Default" nil) file)
|
1997-04-13 02:39:56 +00:00
|
|
|
:group 'shell)
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2006-10-09 09:04:23 +00:00
|
|
|
;; Note: There are no explicit references to the variable `explicit-csh-args'.
|
|
|
|
;; It is used implicitly by M-x shell when the shell is `csh'.
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom explicit-csh-args
|
1990-11-05 10:06:02 +00:00
|
|
|
(if (eq system-type 'hpux)
|
|
|
|
;; -T persuades HP's csh not to think it is smarter
|
|
|
|
;; than us about what terminal modes to use.
|
|
|
|
'("-i" "-T")
|
|
|
|
'("-i"))
|
2006-05-17 21:57:25 +00:00
|
|
|
"Args passed to inferior shell by \\[shell], if the shell is csh.
|
1997-04-13 02:39:56 +00:00
|
|
|
Value is a list of strings, which may be nil."
|
|
|
|
:type '(repeat (string :tag "Argument"))
|
|
|
|
:group 'shell)
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2006-10-09 09:04:23 +00:00
|
|
|
;; Note: There are no explicit references to the variable `explicit-bash-args'.
|
|
|
|
;; It is used implicitly by M-x shell when the interactive shell is `bash'.
|
2002-06-28 18:50:36 +00:00
|
|
|
(defcustom explicit-bash-args
|
2013-07-14 19:33:54 -07:00
|
|
|
;; Tell bash not to use readline. It's safe to assume --noediting now,
|
|
|
|
;; as it was introduced in 1996 in Bash version 2.
|
|
|
|
'("--noediting" "-i")
|
2006-05-17 21:57:25 +00:00
|
|
|
"Args passed to inferior shell by \\[shell], if the shell is bash.
|
2002-06-28 18:50:36 +00:00
|
|
|
Value is a list of strings, which may be nil."
|
|
|
|
:type '(repeat (string :tag "Argument"))
|
|
|
|
:group 'shell)
|
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-input-autoexpand 'history
|
2006-05-17 21:57:25 +00:00
|
|
|
"If non-nil, expand input command history references on completion.
|
1994-01-09 17:11:57 +00:00
|
|
|
This mirrors the optional behavior of tcsh (its autoexpand and histlit).
|
|
|
|
|
|
|
|
If the value is `input', then the expansion is seen on input.
|
|
|
|
If the value is `history', then the expansion is only when inserting
|
|
|
|
into the buffer's input ring. See also `comint-magic-space' and
|
2011-04-20 19:31:06 -03:00
|
|
|
`comint-dynamic-complete-functions'.
|
1994-01-09 17:11:57 +00:00
|
|
|
|
|
|
|
This variable supplies a default for `comint-input-autoexpand',
|
1997-04-13 02:39:56 +00:00
|
|
|
for Shell mode only."
|
1998-09-18 09:20:28 +00:00
|
|
|
:type '(choice (const :tag "off" nil)
|
|
|
|
(const input)
|
|
|
|
(const history)
|
|
|
|
(const :tag "on" t))
|
1998-10-17 15:29:39 +00:00
|
|
|
:group 'shell)
|
1994-01-09 17:11:57 +00:00
|
|
|
|
2022-09-30 20:28:15 +02:00
|
|
|
(defcustom shell-fontify-input-enable t
|
2022-09-11 12:59:02 +02:00
|
|
|
"Enable fontification of input in shell buffers.
|
2022-09-09 20:10:01 +02:00
|
|
|
This variable only has effect when the shell is started. Use the
|
2022-09-30 20:28:15 +02:00
|
|
|
command `comint-fontify-input-mode' to toggle fontification of
|
|
|
|
input."
|
2022-09-09 20:10:01 +02:00
|
|
|
:type 'boolean
|
|
|
|
:group 'shell
|
|
|
|
:safe 'booleanp
|
|
|
|
:version "29.1")
|
|
|
|
|
|
|
|
(defcustom shell-indirect-setup-hook nil
|
2022-09-11 12:59:02 +02:00
|
|
|
"Hook run in an indirect buffer for input fontification.
|
|
|
|
Input fontification and indentation of a `shell-mode' buffer, if
|
|
|
|
enabled, is performed in an indirect buffer, whose indentation
|
|
|
|
and syntax highlighting is set up with `sh-mode'. In addition to
|
|
|
|
`comint-indirect-setup-hook', run this hook with the indirect
|
|
|
|
buffer as the current buffer after its setup is done. This can
|
2022-09-29 15:19:01 +02:00
|
|
|
be used to further customize fontification and other behavior of
|
2022-09-11 12:59:02 +02:00
|
|
|
the indirect buffer."
|
2023-09-17 10:00:20 -03:00
|
|
|
:type 'hook
|
2022-09-09 20:10:01 +02:00
|
|
|
:group 'shell
|
|
|
|
:version "29.1")
|
|
|
|
|
2022-09-09 20:12:26 +02:00
|
|
|
(defcustom shell-highlight-undef-enable nil
|
|
|
|
"Enable highlighting of undefined commands in shell buffers.
|
|
|
|
This variable only has effect when the shell is started. Use the
|
|
|
|
command `shell-highlight-undef-mode' to toggle highlighting of
|
|
|
|
undefined commands."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'shell
|
|
|
|
:safe 'booleanp
|
|
|
|
:version "29.1")
|
|
|
|
|
1990-11-05 10:06:02 +00:00
|
|
|
(defvar shell-dirstack nil
|
1992-05-30 21:11:25 +00:00
|
|
|
"List of directories saved by pushd in this buffer's shell.
|
|
|
|
Thus, this does not include the shell's current directory.")
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2023-06-26 22:32:07 -06:00
|
|
|
(defvaralias 'shell-dirtrackp 'shell-dirtrack-mode
|
|
|
|
"Non-nil in a shell buffer means directory tracking is enabled.
|
|
|
|
Directory tracking (`shell-dirtrack-mode') is automatically enabled
|
|
|
|
when `shell-mode' is activated.")
|
1994-03-02 16:55:16 +00:00
|
|
|
|
1993-03-25 01:55:24 +00:00
|
|
|
(defvar shell-last-dir nil
|
|
|
|
"Keep track of last directory for ksh `cd -' command.")
|
|
|
|
|
1994-04-24 10:50:41 +00:00
|
|
|
(defvar shell-dirstack-query nil
|
2007-03-04 17:47:19 +00:00
|
|
|
"Command used by `shell-resync-dirs' to query the shell.")
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2021-06-09 11:44:34 +02:00
|
|
|
(defcustom shell-has-auto-cd nil
|
|
|
|
"If non-nil, `shell-mode' handles implicit \"cd\" commands.
|
|
|
|
Implicit \"cd\" is changing the directory if the command is a directory.
|
|
|
|
You can make this variable buffer-local to change it, per shell-mode instance.
|
|
|
|
Useful for shells like zsh that has this feature."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'shell-directories
|
|
|
|
:version "28.1")
|
|
|
|
|
2023-03-31 09:57:32 +02:00
|
|
|
(defcustom shell-get-old-input-include-continuation-lines nil
|
|
|
|
"Whether `shell-get-old-input' includes \"\\\" lines."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'shell
|
|
|
|
:version "30.1")
|
|
|
|
|
2022-05-15 02:09:46 +02:00
|
|
|
(defcustom shell-kill-buffer-on-exit nil
|
|
|
|
"Kill a shell buffer after the shell process terminates."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'shell
|
|
|
|
:version "29.1")
|
|
|
|
|
2010-10-10 16:12:30 -07:00
|
|
|
(defvar shell-mode-map
|
2019-10-09 09:22:38 +02:00
|
|
|
(let ((map (make-sparse-keymap)))
|
2010-10-10 16:12:30 -07:00
|
|
|
(define-key map "\C-c\C-f" 'shell-forward-command)
|
|
|
|
(define-key map "\C-c\C-b" 'shell-backward-command)
|
2011-04-20 19:31:06 -03:00
|
|
|
(define-key map "\t" 'completion-at-point)
|
2010-10-10 16:12:30 -07:00
|
|
|
(define-key map (kbd "M-RET") 'shell-resync-dirs)
|
|
|
|
(define-key map "\M-?" 'comint-dynamic-list-filename-completions)
|
2020-10-17 13:16:24 +02:00
|
|
|
(define-key map (kbd "C-x n d") 'shell-narrow-to-prompt)
|
2010-10-10 16:12:30 -07:00
|
|
|
(define-key map [menu-bar completion]
|
|
|
|
(cons "Complete"
|
|
|
|
(copy-keymap (lookup-key comint-mode-map [menu-bar completion]))))
|
|
|
|
(define-key-after (lookup-key map [menu-bar completion])
|
|
|
|
[complete-env-variable] '("Complete Env. Variable Name" .
|
|
|
|
shell-dynamic-complete-environment-variable)
|
|
|
|
'complete-file)
|
|
|
|
(define-key-after (lookup-key map [menu-bar completion])
|
|
|
|
[expand-directory] '("Expand Directory Reference" .
|
|
|
|
shell-replace-by-expanded-directory)
|
|
|
|
'complete-expand)
|
|
|
|
map))
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2022-11-08 23:18:23 -08:00
|
|
|
(defvar-keymap shell-repeat-map
|
|
|
|
:doc "Keymap to repeat shell key sequences. Used in `repeat-mode'."
|
2022-12-22 10:03:09 +02:00
|
|
|
:repeat t
|
2022-11-08 23:18:23 -08:00
|
|
|
"C-f" #'shell-forward-command
|
|
|
|
"C-b" #'shell-backward-command)
|
|
|
|
|
1997-04-13 02:39:56 +00:00
|
|
|
(defcustom shell-mode-hook '()
|
2009-09-24 01:37:14 +00:00
|
|
|
"Hook for customizing Shell mode."
|
1997-04-13 02:39:56 +00:00
|
|
|
:type 'hook
|
|
|
|
:group 'shell)
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1994-10-07 10:04:06 +00:00
|
|
|
(defvar shell-font-lock-keywords
|
2000-08-22 10:06:55 +00:00
|
|
|
'(("[ \t]\\([+-][^ \t\n]+\\)" 1 font-lock-comment-face)
|
1997-04-17 07:35:38 +00:00
|
|
|
("^[^ \t\n]+:.*" . font-lock-string-face)
|
|
|
|
("^\\[[1-9][0-9]*\\]" . font-lock-string-face))
|
1994-10-07 10:04:06 +00:00
|
|
|
"Additional expressions to highlight in Shell mode.")
|
2001-01-28 03:43:35 +00:00
|
|
|
|
2019-07-22 13:04:14 +02:00
|
|
|
(defvar-local shell--start-prog nil
|
|
|
|
"Shell file name started in `shell'.")
|
|
|
|
(put 'shell--start-prog 'permanent-local t)
|
|
|
|
|
2024-06-02 19:30:12 +02:00
|
|
|
(defcustom shell-history-file-name nil
|
|
|
|
"The history file name used in `shell-mode'.
|
|
|
|
When it is a string, this file name will be used.
|
|
|
|
When it is nil, the environment variable HISTFILE is used.
|
|
|
|
When it is t, no history file name is used in `shell-mode'.
|
|
|
|
|
|
|
|
The settings obey whether `shell-mode' is invoked in a remote buffer.
|
|
|
|
In that case, HISTFILE is taken from the remote host, and the string is
|
|
|
|
interpreted as local file name on the remote host.
|
|
|
|
|
|
|
|
If `shell-mode' is invoked in a local buffer, and no history file name
|
|
|
|
can be determined, a default according to the shell type is used."
|
|
|
|
:type '(choice (const :tag "Default" nil) (const :tag "Suppress" t) file)
|
Prefer defcustom :local specifier
* lisp/dirtrack.el (dirtrack-list):
* lisp/emacs-lisp/lisp.el (defun-prompt-regexp):
* lisp/emulation/viper-init.el
(viper-related-files-and-buffers-ring):
* lisp/emulation/viper-util.el (viper-syntax-preference):
* lisp/erc/erc.el (erc-ignore-list):
* lisp/files.el (buffer-offer-save, backup-by-copying-when-mismatch):
* lisp/find-file.el (ff-pre-find-hook, ff-pre-load-hook)
(ff-post-load-hook, ff-not-found-hook, ff-file-created-hook)
(ff-case-fold-search, ff-always-in-other-window)
(ff-ignore-include, ff-quiet-mode, ff-other-file-alist)
(ff-search-directories):
* lisp/mh-e/mh-e.el (mh-scan-prog):
* lisp/newcomment.el (comment-column):
* lisp/obsolete/rlogin.el (rlogin-directory-tracking-mode):
* lisp/play/decipher.el (decipher-ignore-spaces):
* lisp/plstore.el (plstore-encrypt-to):
* lisp/proced.el (proced-format, proced-filter, proced-sort)
(proced-descend, proced-auto-update-flag, proced-tree-flag):
* lisp/progmodes/fortran.el (fortran-line-length):
* lisp/shell.el (shell-history-file-name):
* lisp/simple.el (goal-column, fill-prefix):
* lisp/vc/ediff-init.el (ediff-use-faces)
(ediff-highlight-all-diffs, ediff-autostore-merges):
* lisp/vc/ediff-merg.el (ediff-show-clashes-only)
(ediff-skip-merge-regions-that-differ-from-default): Prefer defcustom
:local specifier to using 'make-variable-buffer-local' directly.
2024-10-04 01:36:41 +02:00
|
|
|
:local 'permanent-only
|
2024-06-02 19:30:12 +02:00
|
|
|
:version "30.1")
|
|
|
|
|
1990-11-05 10:06:02 +00:00
|
|
|
;;; Basic Procedures
|
|
|
|
|
2012-05-15 12:58:35 -04:00
|
|
|
(defun shell--unquote&requote-argument (qstr &optional upos)
|
|
|
|
(unless upos (setq upos 0))
|
|
|
|
(let* ((qpos 0)
|
|
|
|
(dquotes nil)
|
|
|
|
(ustrs '())
|
|
|
|
(re (concat
|
|
|
|
"[\"']"
|
|
|
|
"\\|\\$\\(?:\\([[:alpha:]][[:alnum:]]*\\)"
|
|
|
|
"\\|{\\(?1:[^{}]+\\)}\\)"
|
|
|
|
(when (memq system-type '(ms-dos windows-nt))
|
2020-02-17 18:26:47 +01:00
|
|
|
"\\|%\\(?1:[^\\/]*\\)%")
|
2012-05-15 12:58:35 -04:00
|
|
|
(when comint-file-name-quote-list
|
|
|
|
"\\|\\\\\\(.\\)")))
|
|
|
|
(qupos nil)
|
|
|
|
(push (lambda (str end)
|
|
|
|
(push str ustrs)
|
|
|
|
(setq upos (- upos (length str)))
|
|
|
|
(unless (or qupos (> upos 0))
|
|
|
|
(setq qupos (if (< end 0) (- end) (+ upos end))))))
|
|
|
|
match)
|
|
|
|
(while (setq match (string-match re qstr qpos))
|
|
|
|
(funcall push (substring qstr qpos match) match)
|
|
|
|
(cond
|
|
|
|
((match-beginning 2) (funcall push (match-string 2 qstr) (match-end 0)))
|
|
|
|
((match-beginning 1) (funcall push (getenv (match-string 1 qstr))
|
|
|
|
(- (match-end 0))))
|
|
|
|
((eq (aref qstr match) ?\") (setq dquotes (not dquotes)))
|
|
|
|
((eq (aref qstr match) ?\')
|
|
|
|
(cond
|
2016-10-26 14:31:12 -04:00
|
|
|
;; Treat single quote as text if inside double quotes.
|
2012-05-15 12:58:35 -04:00
|
|
|
(dquotes (funcall push "'" (match-end 0)))
|
2016-10-26 14:31:12 -04:00
|
|
|
((< (1+ match) (length qstr))
|
2012-05-15 12:58:35 -04:00
|
|
|
(let ((end (string-match "'" qstr (1+ match))))
|
2016-10-26 14:31:12 -04:00
|
|
|
(unless end
|
|
|
|
(setq end (length qstr))
|
|
|
|
(set-match-data (list match (length qstr))))
|
|
|
|
(funcall push (substring qstr (1+ match) end) end)))
|
|
|
|
;; Ignore if at the end of string.
|
2012-05-15 12:58:35 -04:00
|
|
|
(t nil)))
|
|
|
|
(t (error "Unexpected case in shell--unquote&requote-argument!")))
|
|
|
|
(setq qpos (match-end 0)))
|
|
|
|
(funcall push (substring qstr qpos) (length qstr))
|
|
|
|
(list (mapconcat #'identity (nreverse ustrs) "")
|
|
|
|
qupos #'comint-quote-filename)))
|
|
|
|
|
|
|
|
(defun shell--unquote-argument (str)
|
|
|
|
(car (shell--unquote&requote-argument str)))
|
|
|
|
(defun shell--requote-argument (upos qstr)
|
|
|
|
;; See `completion-table-with-quoting'.
|
|
|
|
(let ((res (shell--unquote&requote-argument qstr upos)))
|
|
|
|
(cons (nth 1 res) (nth 2 res))))
|
|
|
|
|
|
|
|
(defun shell--parse-pcomplete-arguments ()
|
2011-08-23 01:21:09 -04:00
|
|
|
"Parse whitespace separated arguments in the current region."
|
2012-05-15 12:58:35 -04:00
|
|
|
;; FIXME: share code with shell--unquote&requote-argument.
|
2011-08-23 01:21:09 -04:00
|
|
|
(let ((begin (save-excursion (shell-backward-command 1) (point)))
|
|
|
|
(end (point))
|
|
|
|
begins args)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char begin)
|
|
|
|
(while (< (point) end)
|
2020-01-16 20:21:37 +01:00
|
|
|
(skip-chars-forward " \t\n;")
|
2011-08-23 01:21:09 -04:00
|
|
|
(push (point) begins)
|
2011-08-28 01:15:17 -04:00
|
|
|
(let ((arg ()))
|
|
|
|
(while (looking-at
|
2022-07-04 14:52:50 +02:00
|
|
|
(concat
|
|
|
|
"\\(?:[^\s\t\n\\\"';]+"
|
|
|
|
"\\|'\\([^']*\\)'?"
|
|
|
|
"\\|\"\\(\\(?:[^\"\\]\\|\\\\.\\)*\\)\"?"
|
|
|
|
"\\|\\\\\\(\\(?:.\\|\n\\)?\\)\\)"))
|
2011-08-28 01:15:17 -04:00
|
|
|
(goto-char (match-end 0))
|
|
|
|
(cond
|
|
|
|
((match-beginning 3) ;Backslash escape.
|
2012-05-05 00:18:49 -04:00
|
|
|
(push (cond
|
2012-05-15 12:58:35 -04:00
|
|
|
((null comint-file-name-quote-list)
|
2012-05-05 00:18:49 -04:00
|
|
|
(goto-char (match-beginning 3)) "\\")
|
|
|
|
((= (match-beginning 3) (match-end 3)) "\\")
|
|
|
|
(t (match-string 3)))
|
2011-08-28 01:15:17 -04:00
|
|
|
arg))
|
|
|
|
((match-beginning 2) ;Double quote.
|
2012-05-15 12:58:35 -04:00
|
|
|
(push (if (null comint-file-name-quote-list) (match-string 2)
|
2012-05-09 13:20:24 -04:00
|
|
|
(replace-regexp-in-string
|
|
|
|
"\\\\\\(.\\)" "\\1" (match-string 2)))
|
2011-08-28 01:15:17 -04:00
|
|
|
arg))
|
|
|
|
((match-beginning 1) ;Single quote.
|
|
|
|
(push (match-string 1) arg))
|
|
|
|
(t (push (match-string 0) arg))))
|
|
|
|
(push (mapconcat #'identity (nreverse arg) "") args)))
|
2011-08-23 01:21:09 -04:00
|
|
|
(cons (nreverse args) (nreverse begins)))))
|
2011-05-16 19:38:04 -07:00
|
|
|
|
2023-03-31 09:57:32 +02:00
|
|
|
(defun shell-get-old-input ()
|
|
|
|
"Default for `comint-get-old-input' in `shell-mode'.
|
|
|
|
If `comint-use-prompt-regexp' is nil, then either
|
|
|
|
return the current input field (if point is on an input field), or the
|
|
|
|
current line (if point is on an output field).
|
|
|
|
If `comint-use-prompt-regexp' is non-nil, then return
|
|
|
|
the current line, with any initial string matching the regexp
|
|
|
|
`comint-prompt-regexp' removed.
|
|
|
|
In either case, if `shell-get-old-input-include-continuation-lines'
|
|
|
|
is non-nil and the current line ends with a backslash, the next
|
|
|
|
line is also included and examined for a backslash, ending with a
|
|
|
|
final line without a backslash."
|
|
|
|
(let (field-prop bof)
|
|
|
|
(if (and (not comint-use-prompt-regexp)
|
|
|
|
;; Make sure we're in an input rather than output field.
|
|
|
|
(not (setq field-prop (get-char-property
|
|
|
|
(setq bof (field-beginning)) 'field))))
|
|
|
|
(field-string-no-properties bof)
|
|
|
|
(comint-bol)
|
|
|
|
(let ((start (point)))
|
|
|
|
(cond ((or comint-use-prompt-regexp
|
|
|
|
(eq field-prop 'output))
|
|
|
|
(goto-char (line-end-position))
|
|
|
|
(when shell-get-old-input-include-continuation-lines
|
|
|
|
;; Include continuation lines as long as the current
|
|
|
|
;; line ends with a backslash.
|
|
|
|
(while (and (not (eobp))
|
|
|
|
(= (char-before) ?\\))
|
|
|
|
(goto-char (line-end-position 2)))))
|
|
|
|
(t
|
|
|
|
(goto-char (field-end))))
|
|
|
|
(buffer-substring-no-properties start (point))))))
|
|
|
|
|
2021-07-15 17:04:00 +02:00
|
|
|
;;;###autoload
|
2021-07-15 10:29:04 +02:00
|
|
|
(defun split-string-shell-command (string)
|
2021-07-15 10:25:41 +02:00
|
|
|
"Split STRING (a shell command) into a list of strings.
|
|
|
|
General shell syntax, like single and double quoting, as well as
|
|
|
|
backslash quoting, is respected."
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert string)
|
|
|
|
(let ((comint-file-name-quote-list shell-file-name-quote-list))
|
|
|
|
(car (shell--parse-pcomplete-arguments)))))
|
|
|
|
|
2012-01-05 22:51:05 +08:00
|
|
|
(defun shell-command-completion-function ()
|
|
|
|
"Completion function for shell command names.
|
|
|
|
This is the value of `pcomplete-command-completion-function' for
|
|
|
|
Shell buffers. It implements `shell-completion-execonly' for
|
|
|
|
`pcomplete' completion."
|
2020-09-27 22:07:14 -04:00
|
|
|
(if (pcomplete-match "/")
|
|
|
|
(pcomplete-here (pcomplete-entries nil
|
|
|
|
(if shell-completion-execonly
|
2021-02-12 16:08:01 -05:00
|
|
|
#'file-executable-p)))
|
2020-09-27 22:07:14 -04:00
|
|
|
(pcomplete-here
|
|
|
|
(nth 2 (shell--command-completion-data)))))
|
2012-01-05 22:51:05 +08:00
|
|
|
|
2011-05-12 09:55:10 -03:00
|
|
|
(defun shell-completion-vars ()
|
|
|
|
"Setup completion vars for `shell-mode' and `read-shell-command'."
|
2020-12-08 08:50:54 +01:00
|
|
|
(setq-local comint-completion-fignore
|
|
|
|
shell-completion-fignore)
|
|
|
|
(setq-local comint-delimiter-argument-list
|
|
|
|
shell-delimiter-argument-list)
|
|
|
|
(setq-local comint-file-name-chars shell-file-name-chars)
|
|
|
|
(setq-local comint-file-name-quote-list
|
|
|
|
shell-file-name-quote-list)
|
|
|
|
(setq-local comint-file-name-prefix
|
|
|
|
(or (file-remote-p default-directory) ""))
|
|
|
|
(setq-local comint-dynamic-complete-functions
|
|
|
|
shell-dynamic-complete-functions)
|
2012-05-15 12:58:35 -04:00
|
|
|
(setq-local comint-unquote-function #'shell--unquote-argument)
|
|
|
|
(setq-local comint-requote-function #'shell--requote-argument)
|
2020-12-08 08:50:54 +01:00
|
|
|
(setq-local pcomplete-parse-arguments-function
|
|
|
|
#'shell--parse-pcomplete-arguments)
|
|
|
|
(setq-local pcomplete-termination-string
|
|
|
|
(cond ((not comint-completion-addsuffix) "")
|
|
|
|
((stringp comint-completion-addsuffix)
|
|
|
|
comint-completion-addsuffix)
|
|
|
|
((not (consp comint-completion-addsuffix)) " ")
|
|
|
|
(t (cdr comint-completion-addsuffix))))
|
|
|
|
(setq-local pcomplete-command-completion-function
|
|
|
|
#'shell-command-completion-function)
|
2011-06-04 09:31:34 -03:00
|
|
|
;; Don't use pcomplete's defaulting mechanism, rely on
|
|
|
|
;; shell-dynamic-complete-functions instead.
|
2020-12-08 08:50:54 +01:00
|
|
|
(setq-local pcomplete-default-completion-function #'ignore)
|
2023-08-20 09:41:07 +02:00
|
|
|
;; Do not expand remote file names.
|
2023-09-10 09:53:47 +02:00
|
|
|
(setq-local pcomplete-remote-file-ignore
|
|
|
|
(not (file-remote-p default-directory)))
|
2019-03-15 11:15:06 +02:00
|
|
|
(setq-local comint-input-autoexpand shell-input-autoexpand)
|
2011-05-12 09:55:10 -03:00
|
|
|
;; Not needed in shell-mode because it's inherited from comint-mode, but
|
|
|
|
;; placed here for read-shell-command.
|
2018-12-04 12:39:47 -05:00
|
|
|
(add-hook 'completion-at-point-functions #'comint-completion-at-point nil t))
|
2011-05-12 09:55:10 -03:00
|
|
|
|
1997-05-05 00:59:28 +00:00
|
|
|
(put 'shell-mode 'mode-class 'special)
|
|
|
|
|
2022-09-09 20:10:01 +02:00
|
|
|
(defvar sh-shell-file)
|
|
|
|
|
2024-03-29 18:26:38 +03:00
|
|
|
(declare-function w32-application-type "w32proc.c"
|
2024-03-29 10:36:43 -04:00
|
|
|
(program) t)
|
|
|
|
|
2000-11-21 21:33:45 +00:00
|
|
|
(define-derived-mode shell-mode comint-mode "Shell"
|
2021-09-22 20:26:40 +02:00
|
|
|
"Major mode for interacting with an inferior shell.
|
|
|
|
\\<shell-mode-map>
|
1995-02-25 16:10:01 +00:00
|
|
|
\\[comint-send-input] after the end of the process' output sends the text from
|
|
|
|
the end of process to the end of the current line.
|
|
|
|
\\[comint-send-input] before end of process output copies the current line minus the prompt to
|
|
|
|
the end of the buffer and sends it (\\[comint-copy-old-input] just copies the current line).
|
2018-07-18 10:23:20 -04:00
|
|
|
\\[comint-send-invisible] reads a line of text without echoing it, and sends it to
|
1994-03-24 07:51:27 +00:00
|
|
|
the shell. This is useful for entering passwords. Or, add the function
|
|
|
|
`comint-watch-for-password-prompt' to `comint-output-filter-functions'.
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2022-04-22 17:16:42 +02:00
|
|
|
If you want to make multiple shell buffers, rename the \"*shell*\" buffer
|
1995-01-10 12:08:21 +00:00
|
|
|
using \\[rename-buffer] or \\[rename-uniquely] and start a new shell.
|
|
|
|
|
1995-02-25 16:10:01 +00:00
|
|
|
If you want to make shell buffers limited in length, add the function
|
1995-02-25 16:16:57 +00:00
|
|
|
`comint-truncate-buffer' to `comint-output-filter-functions'.
|
1995-02-25 16:10:01 +00:00
|
|
|
|
1990-11-05 10:06:02 +00:00
|
|
|
If you accidentally suspend your process, use \\[comint-continue-subjob]
|
|
|
|
to continue it.
|
|
|
|
|
1995-01-10 12:08:21 +00:00
|
|
|
`cd', `pushd' and `popd' commands given to the shell are watched by Emacs to
|
|
|
|
keep this buffer's default directory the same as the shell's working directory.
|
1995-02-21 13:07:23 +00:00
|
|
|
While directory tracking is enabled, the shell's working directory is displayed
|
|
|
|
by \\[list-buffers] or \\[mouse-buffer-menu] in the `File' field.
|
2012-02-28 00:17:21 -08:00
|
|
|
\\[dirs] queries the shell and resyncs Emacs's idea of what the current
|
1990-11-05 10:06:02 +00:00
|
|
|
directory stack is.
|
2007-10-27 22:15:27 +00:00
|
|
|
\\[shell-dirtrack-mode] turns directory tracking on and off.
|
|
|
|
\(The `dirtrack' package provides an alternative implementation of this
|
2007-10-30 06:39:00 +00:00
|
|
|
feature - see the function `dirtrack-mode'.)
|
1990-11-05 10:06:02 +00:00
|
|
|
|
|
|
|
\\{shell-mode-map}
|
1993-04-29 14:23:22 +00:00
|
|
|
Customization: Entry to this mode runs the hooks on `comint-mode-hook' and
|
1994-03-03 23:37:27 +00:00
|
|
|
`shell-mode-hook' (in that order). Before each input, the hooks on
|
1994-03-03 23:57:27 +00:00
|
|
|
`comint-input-filter-functions' are run. After each shell output, the hooks
|
|
|
|
on `comint-output-filter-functions' are run.
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2001-01-28 03:43:35 +00:00
|
|
|
Variables `shell-cd-regexp', `shell-chdrive-regexp', `shell-pushd-regexp'
|
|
|
|
and `shell-popd-regexp' are used to match their respective commands,
|
|
|
|
while `shell-pushd-tohome', `shell-pushd-dextract' and `shell-pushd-dunique'
|
1996-06-09 20:31:51 +00:00
|
|
|
control the behavior of the relevant command.
|
1993-10-22 02:53:24 +00:00
|
|
|
|
1994-03-08 17:43:07 +00:00
|
|
|
Variables `comint-completion-autolist', `comint-completion-addsuffix',
|
|
|
|
`comint-completion-recexact' and `comint-completion-fignore' control the
|
|
|
|
behavior of file name, command name and variable name completion. Variable
|
|
|
|
`shell-completion-execonly' controls the behavior of command name completion.
|
2005-06-16 16:10:43 +00:00
|
|
|
Variable `shell-completion-fignore' is used to initialize the value of
|
1994-03-08 17:43:07 +00:00
|
|
|
`comint-completion-fignore'.
|
1993-10-22 02:53:24 +00:00
|
|
|
|
|
|
|
Variables `comint-input-ring-file-name' and `comint-input-autoexpand' control
|
2005-08-29 11:08:04 +00:00
|
|
|
the initialization of the input ring history, and history expansion.
|
1993-10-22 02:53:24 +00:00
|
|
|
|
1994-03-03 23:57:27 +00:00
|
|
|
Variables `comint-output-filter-functions', a hook, and
|
1994-03-08 17:43:07 +00:00
|
|
|
`comint-scroll-to-bottom-on-input' and `comint-scroll-to-bottom-on-output'
|
1994-03-03 23:37:27 +00:00
|
|
|
control whether input and output cause the window to scroll to the end of the
|
2022-03-22 19:15:33 +01:00
|
|
|
buffer.
|
|
|
|
|
|
|
|
By default, shell mode does nothing special when it receives a
|
|
|
|
\"bell\" character (C-g or ^G). If you
|
2022-04-22 17:16:42 +02:00
|
|
|
(add-hook \\='comint-output-filter-functions #\\='shell-filter-ring-bell nil t)
|
2022-03-22 19:15:33 +01:00
|
|
|
from `shell-mode-hook', Emacs will call the `ding' function
|
|
|
|
whenever it receives the bell character in output from a
|
|
|
|
command."
|
2021-02-14 12:52:00 +01:00
|
|
|
:interactive nil
|
2022-09-09 20:10:01 +02:00
|
|
|
:after-hook
|
2022-09-09 20:12:26 +02:00
|
|
|
(unless comint-use-prompt-regexp
|
2022-09-30 20:28:15 +02:00
|
|
|
(if shell-fontify-input-enable
|
|
|
|
(comint-fontify-input-mode))
|
2022-09-09 20:12:26 +02:00
|
|
|
(if shell-highlight-undef-enable
|
|
|
|
(shell-highlight-undef-mode)))
|
2022-09-09 20:10:01 +02:00
|
|
|
|
1993-10-22 02:53:24 +00:00
|
|
|
(setq comint-prompt-regexp shell-prompt-pattern)
|
2011-05-12 09:55:10 -03:00
|
|
|
(shell-completion-vars)
|
2017-01-27 11:39:31 +02:00
|
|
|
(setq-local paragraph-separate "\\'")
|
|
|
|
(setq-local paragraph-start comint-prompt-regexp)
|
|
|
|
(setq-local font-lock-defaults '(shell-font-lock-keywords t))
|
2025-03-06 12:04:57 +01:00
|
|
|
(setq-local bookmark-make-record-function #'shell-bookmark-make-record)
|
2017-01-27 11:39:31 +02:00
|
|
|
(setq-local shell-dirstack nil)
|
|
|
|
(setq-local shell-last-dir nil)
|
2023-03-31 09:57:32 +02:00
|
|
|
(setq-local comint-get-old-input #'shell-get-old-input)
|
2017-01-27 11:39:31 +02:00
|
|
|
;; People expect Shell mode to keep the last line of output at
|
|
|
|
;; window bottom.
|
|
|
|
(setq-local scroll-conservatively 101)
|
2009-09-25 04:35:14 +00:00
|
|
|
(shell-dirtrack-mode 1)
|
2012-02-19 21:59:42 +08:00
|
|
|
|
|
|
|
;; By default, ansi-color applies faces using overlays. This is
|
|
|
|
;; very inefficient in Shell buffers (e.g. Bug#10835). We use a
|
|
|
|
;; custom `ansi-color-apply-face-function' to convert color escape
|
|
|
|
;; sequences into `font-lock-face' properties.
|
2012-11-30 16:24:53 +08:00
|
|
|
(setq-local ansi-color-apply-face-function #'shell-apply-ansi-color)
|
|
|
|
(shell-reapply-ansi-color)
|
2012-02-19 21:59:42 +08:00
|
|
|
|
2022-09-09 20:10:01 +02:00
|
|
|
(add-hook 'comint-indirect-setup-hook
|
|
|
|
#'shell-indirect-setup-hook 'append t)
|
|
|
|
(setq comint-indirect-setup-function
|
|
|
|
(let ((shell shell--start-prog))
|
|
|
|
(lambda ()
|
|
|
|
(require 'sh-script)
|
|
|
|
(cl-letf
|
|
|
|
(((default-value 'sh-shell-file)
|
|
|
|
(or shell sh-shell-file))
|
|
|
|
(inhibit-message t)
|
|
|
|
(message-log-max nil))
|
|
|
|
(sh-mode)))))
|
|
|
|
|
2022-09-09 20:13:13 +02:00
|
|
|
(setq-local indent-line-function #'comint-indent-input-line-default)
|
|
|
|
(setq-local indent-region-function
|
|
|
|
#'comint-indent-input-region-default)
|
|
|
|
|
1997-07-20 04:13:45 +00:00
|
|
|
;; This is not really correct, since the shell buffer does not really
|
|
|
|
;; edit this directory. But it is useful in the buffer list and menus.
|
|
|
|
(setq list-buffers-directory (expand-file-name default-directory))
|
1993-10-22 02:53:24 +00:00
|
|
|
;; shell-dependent assignments.
|
2002-05-14 08:46:00 +00:00
|
|
|
(when (ring-empty-p comint-input-ring)
|
2024-06-02 19:30:12 +02:00
|
|
|
(let* ((remote (file-remote-p default-directory))
|
|
|
|
(shell (or shell--start-prog ""))
|
|
|
|
(hfile (cond ((stringp shell-history-file-name)
|
|
|
|
shell-history-file-name)
|
|
|
|
((null shell-history-file-name)
|
|
|
|
(if remote
|
|
|
|
(shell-command-to-string "echo -n $HISTFILE")
|
|
|
|
(getenv "HISTFILE")))))
|
|
|
|
hsize)
|
2019-07-22 13:04:14 +02:00
|
|
|
(and (string-equal hfile "") (setq hfile nil))
|
2024-06-02 19:30:12 +02:00
|
|
|
(when (and (not remote) (not hfile))
|
|
|
|
(setq hfile
|
|
|
|
(cond ((string-equal shell "bash") "~/.bash_history")
|
|
|
|
((string-equal shell "ksh") "~/.sh_history")
|
|
|
|
((string-equal shell "zsh") "~/.zsh_history")
|
|
|
|
(t "~/.history"))))
|
|
|
|
(when (stringp hfile)
|
|
|
|
(setq hsize
|
|
|
|
(if remote
|
|
|
|
(shell-command-to-string "echo -n $HISTSIZE")
|
|
|
|
(getenv "HISTSIZE")))
|
|
|
|
(and (stringp hsize)
|
|
|
|
(integerp (setq hsize (string-to-number hsize)))
|
|
|
|
(> hsize 0)
|
|
|
|
(setq-local comint-input-ring-size hsize))
|
|
|
|
(setq comint-input-ring-file-name
|
|
|
|
(concat remote hfile)))
|
2024-06-28 11:28:33 +02:00
|
|
|
(if (and comint-input-ring-file-name
|
|
|
|
(or (equal comint-input-ring-file-name "")
|
|
|
|
(equal (file-truename comint-input-ring-file-name)
|
|
|
|
(file-truename null-device))))
|
2002-04-03 15:23:59 +00:00
|
|
|
(setq comint-input-ring-file-name nil))
|
|
|
|
;; Arrange to write out the input ring on exit, if the shell doesn't
|
|
|
|
;; do this itself.
|
|
|
|
(if (and comint-input-ring-file-name
|
|
|
|
(string-match shell-dumb-shell-regexp shell))
|
|
|
|
(set-process-sentinel (get-buffer-process (current-buffer))
|
|
|
|
#'shell-write-history-on-exit))
|
|
|
|
(setq shell-dirstack-query
|
|
|
|
(cond ((string-equal shell "sh") "pwd")
|
|
|
|
((string-equal shell "ksh") "echo $PWD ~-")
|
2014-05-22 15:56:49 -04:00
|
|
|
;; Bypass any aliases. TODO all shells could use this.
|
|
|
|
((string-equal shell "bash") "command dirs")
|
2024-03-29 10:36:43 -04:00
|
|
|
((and (string-equal shell "bash.exe")
|
|
|
|
(eq system-type 'windows-nt)
|
|
|
|
(eq (w32-application-type (executable-find "bash.exe"))
|
|
|
|
'msys))
|
|
|
|
"command pwd -W")
|
2016-12-10 17:29:51 -08:00
|
|
|
((string-equal shell "zsh") "dirs -l")
|
2003-06-05 12:02:09 +00:00
|
|
|
(t "dirs")))
|
|
|
|
;; Bypass a bug in certain versions of bash.
|
|
|
|
(when (string-equal shell "bash")
|
2011-04-20 19:31:06 -03:00
|
|
|
(add-hook 'comint-preoutput-filter-functions
|
2020-08-10 13:09:57 +02:00
|
|
|
#'shell-filter-ctrl-a-ctrl-b nil t))
|
|
|
|
|
|
|
|
;; Skip extended history for zsh.
|
|
|
|
(when (string-equal shell "zsh")
|
|
|
|
(setq-local comint-input-ring-file-prefix
|
|
|
|
": [[:digit:]]+:[[:digit:]]+;")))
|
2002-04-03 15:23:59 +00:00
|
|
|
(comint-read-input-ring t)))
|
2000-09-14 21:15:44 +00:00
|
|
|
|
2022-09-09 20:10:01 +02:00
|
|
|
(defun shell-indirect-setup-hook ()
|
|
|
|
"Run `shell-indirect-setup-hook'."
|
|
|
|
(run-hooks 'shell-indirect-setup-hook))
|
|
|
|
|
2012-11-30 16:24:53 +08:00
|
|
|
(defun shell-apply-ansi-color (beg end face)
|
|
|
|
"Apply FACE as the ansi-color face for the text between BEG and END."
|
|
|
|
(when face
|
|
|
|
(put-text-property beg end 'ansi-color-face face)
|
|
|
|
(put-text-property beg end 'font-lock-face face)))
|
|
|
|
|
|
|
|
(defun shell-reapply-ansi-color ()
|
|
|
|
"Reapply ansi-color faces to the existing contents of the buffer."
|
|
|
|
(save-restriction
|
|
|
|
(widen)
|
|
|
|
(let* ((pos (point-min))
|
|
|
|
(end (or (next-single-property-change pos 'ansi-color-face)
|
|
|
|
(point-max)))
|
|
|
|
face)
|
|
|
|
(while end
|
|
|
|
(if (setq face (get-text-property pos 'ansi-color-face))
|
|
|
|
(put-text-property pos (or end (point-max))
|
|
|
|
'font-lock-face face))
|
|
|
|
(setq pos end
|
|
|
|
end (next-single-property-change pos 'ansi-color-face))))))
|
|
|
|
|
2011-04-20 19:31:06 -03:00
|
|
|
(defun shell-filter-ctrl-a-ctrl-b (string)
|
2003-06-05 12:02:09 +00:00
|
|
|
"Remove `^A' and `^B' characters from comint output.
|
|
|
|
|
|
|
|
Bash uses these characters as internal quoting characters in its
|
|
|
|
prompt. Due to a bug in some bash versions (including 2.03,
|
|
|
|
2.04, and 2.05b), they may erroneously show up when bash is
|
|
|
|
started with the `--noediting' option and Select Graphic
|
|
|
|
Rendition (SGR) control sequences (formerly known as ANSI escape
|
|
|
|
sequences) are used to color the prompt.
|
|
|
|
|
2011-04-20 19:31:06 -03:00
|
|
|
This function can be put on `comint-preoutput-filter-functions'."
|
|
|
|
(if (string-match "[\C-a\C-b]" string)
|
|
|
|
(replace-regexp-in-string "[\C-a\C-b]" "" string t t)
|
|
|
|
string))
|
2003-06-05 12:02:09 +00:00
|
|
|
|
2022-03-22 19:15:33 +01:00
|
|
|
(defun shell-filter-ring-bell (string)
|
|
|
|
"Call `ding' if STRING contains a \"^G\" character.
|
|
|
|
This function can be put on `comint-output-filter-functions'."
|
|
|
|
(when (string-search "\a" string)
|
|
|
|
(ding))
|
|
|
|
string)
|
|
|
|
|
2000-09-14 21:15:44 +00:00
|
|
|
(defun shell-write-history-on-exit (process event)
|
|
|
|
"Called when the shell process is stopped.
|
|
|
|
|
|
|
|
Writes the input history to a history file
|
2001-01-28 03:43:35 +00:00
|
|
|
`comint-input-ring-file-name' using `comint-write-input-ring'
|
2000-09-14 21:15:44 +00:00
|
|
|
and inserts a short message in the shell buffer.
|
|
|
|
|
|
|
|
This function is a sentinel watching the shell interpreter process.
|
|
|
|
Sentinels will always get the two parameters PROCESS and EVENT."
|
|
|
|
;; Write history.
|
|
|
|
(comint-write-input-ring)
|
2001-01-28 03:43:35 +00:00
|
|
|
(let ((buf (process-buffer process)))
|
|
|
|
(when (buffer-live-p buf)
|
|
|
|
(with-current-buffer buf
|
|
|
|
(insert (format "\nProcess %s %s\n" process event))))))
|
|
|
|
|
2024-06-01 18:03:42 +03:00
|
|
|
(define-derived-mode shell-command-mode comint-mode "Shell"
|
|
|
|
"Major mode for the output of asynchronous `shell-command'."
|
|
|
|
(setq-local font-lock-defaults '(shell-font-lock-keywords t))
|
|
|
|
;; See comments in `shell-mode'.
|
|
|
|
(setq-local ansi-color-apply-face-function #'shell-apply-ansi-color)
|
|
|
|
(setq list-buffers-directory (expand-file-name default-directory)))
|
|
|
|
|
1992-05-30 21:11:25 +00:00
|
|
|
;;;###autoload
|
2022-05-27 09:14:40 -04:00
|
|
|
(defun shell (&optional buffer file-name)
|
2000-10-27 08:01:52 +00:00
|
|
|
"Run an inferior shell, with I/O through BUFFER (which defaults to `*shell*').
|
|
|
|
Interactively, a prefix arg means to prompt for BUFFER.
|
2007-08-22 19:47:57 +00:00
|
|
|
If `default-directory' is a remote file name, it is also prompted
|
|
|
|
to change if called with a prefix arg.
|
|
|
|
|
2000-10-27 08:01:52 +00:00
|
|
|
If BUFFER exists but shell process is not running, make new shell.
|
|
|
|
If BUFFER exists and shell process is running, just switch to BUFFER.
|
1993-04-29 14:23:22 +00:00
|
|
|
Program used comes from variable `explicit-shell-file-name',
|
1991-05-08 07:47:45 +00:00
|
|
|
or (if that is nil) from the ESHELL environment variable,
|
2006-12-15 21:21:43 +00:00
|
|
|
or (if that is nil) from `shell-file-name'.
|
2022-05-27 09:14:40 -04:00
|
|
|
Non-interactively, it can also be specified via the FILE-NAME arg.
|
|
|
|
|
2006-12-05 14:21:56 +00:00
|
|
|
If a file `~/.emacs_SHELLNAME' exists, or `~/.emacs.d/init_SHELLNAME.sh',
|
2006-12-15 21:17:01 +00:00
|
|
|
it is given as initial input (but this may be lost, due to a timing
|
|
|
|
error, if the shell discards input when it starts up).
|
1992-09-04 07:35:10 +00:00
|
|
|
The buffer is put in Shell mode, giving commands for sending input
|
|
|
|
and controlling the subjobs of the shell. See `shell-mode'.
|
|
|
|
See also the variable `shell-prompt-pattern'.
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2019-10-12 07:10:27 +02:00
|
|
|
\\<shell-mode-map>To specify a coding system for converting non-ASCII characters
|
1997-08-04 03:06:28 +00:00
|
|
|
in the input and output to the shell, use \\[universal-coding-system-argument]
|
|
|
|
before \\[shell]. You can also specify this with \\[set-buffer-process-coding-system]
|
|
|
|
in the shell buffer, after you start the shell.
|
|
|
|
The default comes from `process-coding-system-alist' and
|
|
|
|
`default-process-coding-system'.
|
|
|
|
|
1991-05-08 07:47:45 +00:00
|
|
|
The shell file name (sans directories) is used to make a symbol name
|
1993-01-15 07:02:35 +00:00
|
|
|
such as `explicit-csh-args'. If that symbol is a variable,
|
1990-11-05 10:06:02 +00:00
|
|
|
its value is used as a list of arguments when invoking the shell.
|
|
|
|
Otherwise, one argument `-i' is passed to the shell.
|
|
|
|
|
2019-10-17 18:46:53 +02:00
|
|
|
Make the shell buffer the current buffer, and return it.
|
|
|
|
|
1990-11-05 10:06:02 +00:00
|
|
|
\(Type \\[describe-mode] in the shell buffer for a list of commands.)"
|
2000-10-27 08:01:52 +00:00
|
|
|
(interactive
|
2022-05-29 13:37:44 -04:00
|
|
|
(let* ((buffer
|
|
|
|
(and current-prefix-arg
|
|
|
|
(read-buffer "Shell buffer: "
|
|
|
|
;; If the current buffer is an inactive
|
|
|
|
;; shell buffer, use it as the default.
|
|
|
|
(if (and (eq major-mode 'shell-mode)
|
|
|
|
(null (get-buffer-process
|
|
|
|
(current-buffer))))
|
|
|
|
(buffer-name)
|
|
|
|
(generate-new-buffer-name "*shell*")))))
|
|
|
|
(buf (if (or buffer (not (derived-mode-p 'shell-mode))
|
|
|
|
(comint-check-proc (current-buffer)))
|
|
|
|
(get-buffer-create (or buffer "*shell*"))
|
|
|
|
;; If the current buffer is a dead shell buffer, use it.
|
|
|
|
(current-buffer))))
|
|
|
|
|
|
|
|
(with-current-buffer buf
|
|
|
|
(when (and buffer (file-remote-p default-directory))
|
|
|
|
;; It must be possible to declare a local default-directory.
|
|
|
|
(setq default-directory
|
|
|
|
(expand-file-name
|
|
|
|
(read-directory-name
|
|
|
|
"Default directory: " default-directory default-directory
|
|
|
|
t nil))))
|
|
|
|
(list
|
|
|
|
buffer
|
|
|
|
;; On remote hosts, the local `shell-file-name' might be useless.
|
|
|
|
(with-connection-local-variables
|
|
|
|
(when (and (file-remote-p default-directory)
|
|
|
|
(null explicit-shell-file-name)
|
|
|
|
(null (getenv "ESHELL")))
|
|
|
|
;; `expand-file-name' shall not add the MS Windows volume letter
|
|
|
|
;; (Bug#49229).
|
|
|
|
(replace-regexp-in-string
|
|
|
|
"^[[:alpha:]]:" ""
|
|
|
|
(file-local-name
|
|
|
|
(expand-file-name
|
|
|
|
(read-file-name "Remote shell path: " default-directory
|
|
|
|
shell-file-name t shell-file-name
|
|
|
|
#'file-remote-p))))))))))
|
|
|
|
|
2010-11-23 09:19:54 -05:00
|
|
|
(setq buffer (if (or buffer (not (derived-mode-p 'shell-mode))
|
|
|
|
(comint-check-proc (current-buffer)))
|
|
|
|
(get-buffer-create (or buffer "*shell*"))
|
|
|
|
;; If the current buffer is a dead shell buffer, use it.
|
|
|
|
(current-buffer)))
|
2019-10-17 18:46:53 +02:00
|
|
|
;; The buffer's window must be correctly set when we call comint
|
|
|
|
;; (so that comint sets the COLUMNS env var properly).
|
2024-12-04 09:40:33 +02:00
|
|
|
(pop-to-buffer buffer (append display-buffer--same-window-action
|
|
|
|
'((category . comint))))
|
2019-10-17 18:46:53 +02:00
|
|
|
|
|
|
|
(with-connection-local-variables
|
2022-05-27 09:14:40 -04:00
|
|
|
(when file-name
|
|
|
|
(setq-local explicit-shell-file-name file-name))
|
2019-10-17 18:46:53 +02:00
|
|
|
|
|
|
|
;; Rain or shine, BUFFER must be current by now.
|
|
|
|
(unless (comint-check-proc buffer)
|
|
|
|
(let* ((prog (or explicit-shell-file-name
|
|
|
|
(getenv "ESHELL") shell-file-name))
|
|
|
|
(name (file-name-nondirectory prog))
|
|
|
|
(startfile (concat "~/.emacs_" name))
|
2022-03-17 15:04:07 +01:00
|
|
|
(xargs-name (intern-soft (concat "explicit-" name "-args")))
|
|
|
|
(start-point (point)))
|
2019-10-17 18:46:53 +02:00
|
|
|
(unless (file-exists-p startfile)
|
2021-11-09 07:51:18 +01:00
|
|
|
(setq startfile (locate-user-emacs-file
|
|
|
|
(concat "init_" name ".sh"))))
|
2019-10-17 18:46:53 +02:00
|
|
|
(setq-local shell--start-prog (file-name-nondirectory prog))
|
|
|
|
(apply #'make-comint-in-buffer "shell" buffer prog
|
2022-03-17 15:04:07 +01:00
|
|
|
nil
|
2019-10-17 18:46:53 +02:00
|
|
|
(if (and xargs-name (boundp xargs-name))
|
|
|
|
(symbol-value xargs-name)
|
|
|
|
'("-i")))
|
2022-03-17 15:04:07 +01:00
|
|
|
(shell-mode)
|
|
|
|
(when (file-exists-p startfile)
|
|
|
|
;; Wait until the prompt has appeared.
|
|
|
|
(while (= start-point (point))
|
|
|
|
(sleep-for 0.1))
|
|
|
|
(shell-eval-command
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert-file-contents startfile)
|
|
|
|
(buffer-string)))))))
|
2022-05-15 02:09:46 +02:00
|
|
|
(when shell-kill-buffer-on-exit
|
|
|
|
(let* ((buffer (current-buffer))
|
|
|
|
(process (get-buffer-process buffer))
|
|
|
|
(sentinel (process-sentinel process)))
|
|
|
|
(set-process-sentinel
|
|
|
|
process
|
|
|
|
(lambda (proc event)
|
|
|
|
(when sentinel
|
|
|
|
(funcall sentinel proc event))
|
|
|
|
(unless (buffer-live-p proc)
|
|
|
|
(kill-buffer buffer))))))
|
2001-12-02 07:39:23 +00:00
|
|
|
buffer)
|
1995-03-12 09:39:49 +00:00
|
|
|
|
1990-11-05 10:06:02 +00:00
|
|
|
;;; Directory tracking
|
2006-05-17 21:57:25 +00:00
|
|
|
;;
|
|
|
|
;; This code provides the shell mode input sentinel
|
|
|
|
;; SHELL-DIRECTORY-TRACKER
|
|
|
|
;; that tracks cd, pushd, and popd commands issued to the shell, and
|
|
|
|
;; changes the current directory of the shell buffer accordingly.
|
|
|
|
;;
|
2021-02-05 02:27:57 +01:00
|
|
|
;; This is basically a fragile hack. It has the following failings:
|
2006-05-17 21:57:25 +00:00
|
|
|
;; 1. It doesn't know about the cdpath shell variable.
|
|
|
|
;; 2. It cannot infallibly deal with command sequences, though it does well
|
|
|
|
;; with these and with ignoring commands forked in another shell with ()s.
|
|
|
|
;; 3. More generally, any complex command is going to throw it. Otherwise,
|
|
|
|
;; you'd have to build an entire shell interpreter in Emacs Lisp. Failing
|
|
|
|
;; that, there's no way to catch shell commands where cd's are buried
|
|
|
|
;; inside conditional expressions, aliases, and so forth.
|
|
|
|
;;
|
|
|
|
;; The whole approach is a crock. Shell aliases mess it up. File sourcing
|
|
|
|
;; messes it up. You run other processes under the shell; these each have
|
|
|
|
;; separate working directories, and some have commands for manipulating
|
|
|
|
;; their w.d.'s (e.g., the lcd command in ftp). Some of these programs have
|
|
|
|
;; commands that do *not* affect the current w.d. at all, but look like they
|
|
|
|
;; do (e.g., the cd command in ftp). In shells that allow you job
|
|
|
|
;; control, you can switch between jobs, all having different w.d.'s. So
|
|
|
|
;; simply saying %3 can shift your w.d..
|
|
|
|
;;
|
|
|
|
;; The solution is to relax, not stress out about it, and settle for
|
|
|
|
;; a hack that works pretty well in typical circumstances. Remember
|
|
|
|
;; that a half-assed solution is more in keeping with the spirit of Unix,
|
|
|
|
;; anyway. Blech.
|
|
|
|
;;
|
|
|
|
;; One good hack not implemented here for users of programmable shells
|
|
|
|
;; is to program up the shell w.d. manipulation commands to output
|
|
|
|
;; a coded command sequence to the tty. Something like
|
|
|
|
;; ESC | <cwd> |
|
|
|
|
;; where <cwd> is the new current working directory. Then trash the
|
|
|
|
;; directory tracking machinery currently used in this package, and
|
|
|
|
;; replace it with a process filter that watches for and strips out
|
|
|
|
;; these messages.
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2023-06-26 22:32:07 -06:00
|
|
|
(define-minor-mode shell-dirtrack-mode
|
|
|
|
"Toggle directory tracking in this shell buffer (Shell Dirtrack mode).
|
|
|
|
This assigns a buffer-local non-nil value to `shell-dirtrackp'.
|
|
|
|
|
|
|
|
The `dirtrack' package provides an alternative implementation of
|
|
|
|
this feature; see the function `dirtrack-mode'. Also see
|
|
|
|
`comint-osc-directory-tracker' for an escape-sequence based
|
|
|
|
solution."
|
|
|
|
:lighter nil
|
|
|
|
:interactive (shell-mode)
|
|
|
|
(setq list-buffers-directory (if shell-dirtrack-mode default-directory))
|
|
|
|
(if shell-dirtrack-mode
|
|
|
|
(add-hook 'comint-input-filter-functions #'shell-directory-tracker nil t)
|
|
|
|
(remove-hook 'comint-input-filter-functions #'shell-directory-tracker t)))
|
|
|
|
|
1990-11-05 10:06:02 +00:00
|
|
|
(defun shell-directory-tracker (str)
|
|
|
|
"Tracks cd, pushd and popd commands issued to the shell.
|
|
|
|
This function is called on each input passed to the shell.
|
|
|
|
It watches for cd, pushd and popd commands and sets the buffer's
|
|
|
|
default directory to track these commands.
|
|
|
|
|
2007-10-27 22:15:27 +00:00
|
|
|
You may toggle this tracking on and off with \\[shell-dirtrack-mode].
|
2006-05-17 21:57:25 +00:00
|
|
|
If Emacs gets confused, you can resync with the shell with \\[dirs].
|
2007-10-30 06:39:00 +00:00
|
|
|
\(The `dirtrack' package provides an alternative implementation of this
|
|
|
|
feature - see the function `dirtrack-mode'.)
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1996-06-09 20:31:51 +00:00
|
|
|
See variables `shell-cd-regexp', `shell-chdrive-regexp', `shell-pushd-regexp',
|
2001-01-28 03:43:35 +00:00
|
|
|
and `shell-popd-regexp', while `shell-pushd-tohome', `shell-pushd-dextract',
|
1996-06-09 20:31:51 +00:00
|
|
|
and `shell-pushd-dunique' control the behavior of the relevant command.
|
1993-10-22 02:53:24 +00:00
|
|
|
|
1993-04-29 14:23:22 +00:00
|
|
|
Environment variables are expanded, see function `substitute-in-file-name'."
|
2023-06-26 22:32:07 -06:00
|
|
|
(if shell-dirtrack-mode
|
1993-10-22 02:53:24 +00:00
|
|
|
;; We fail gracefully if we think the command will fail in the shell.
|
2014-04-06 18:27:32 -07:00
|
|
|
;;; (with-demoted-errors "Directory tracker failure: %s"
|
|
|
|
;; This fails so often that it seems better to just ignore errors (?).
|
|
|
|
;; Eg even: foo=/tmp; cd $foo is beyond us (bug#17159).
|
|
|
|
(ignore-errors
|
|
|
|
(let ((start (progn (string-match
|
2003-06-12 22:20:49 +00:00
|
|
|
(concat "^" shell-command-separator-regexp)
|
|
|
|
str) ; skip whitespace
|
1993-10-22 02:53:24 +00:00
|
|
|
(match-end 0)))
|
2011-05-26 21:54:56 -04:00
|
|
|
(case-fold-search)
|
2021-06-09 11:44:34 +02:00
|
|
|
end cmd arg1 cmd-subst-fn)
|
1993-10-22 02:53:24 +00:00
|
|
|
(while (string-match shell-command-regexp str start)
|
|
|
|
(setq end (match-end 0)
|
|
|
|
cmd (comint-arguments (substring str start end) 0 0)
|
|
|
|
arg1 (comint-arguments (substring str start end) 1 1))
|
1999-07-20 04:16:51 +00:00
|
|
|
(if arg1
|
|
|
|
(setq arg1 (shell-unquote-argument arg1)))
|
2021-06-09 11:44:34 +02:00
|
|
|
(if shell-has-auto-cd
|
|
|
|
(setq cmd-subst-fn (comint-substitute-in-file-name cmd)))
|
1995-06-19 22:54:58 +00:00
|
|
|
(cond ((string-match (concat "\\`\\(" shell-popd-regexp
|
|
|
|
"\\)\\($\\|[ \t]\\)")
|
|
|
|
cmd)
|
1996-06-09 20:31:51 +00:00
|
|
|
(shell-process-popd (comint-substitute-in-file-name arg1)))
|
1995-06-19 22:54:58 +00:00
|
|
|
((string-match (concat "\\`\\(" shell-pushd-regexp
|
|
|
|
"\\)\\($\\|[ \t]\\)")
|
|
|
|
cmd)
|
1996-06-09 20:31:51 +00:00
|
|
|
(shell-process-pushd (comint-substitute-in-file-name arg1)))
|
1995-06-19 22:54:58 +00:00
|
|
|
((string-match (concat "\\`\\(" shell-cd-regexp
|
|
|
|
"\\)\\($\\|[ \t]\\)")
|
|
|
|
cmd)
|
1996-06-09 20:31:51 +00:00
|
|
|
(shell-process-cd (comint-substitute-in-file-name arg1)))
|
|
|
|
((and shell-chdrive-regexp
|
|
|
|
(string-match (concat "\\`\\(" shell-chdrive-regexp
|
|
|
|
"\\)\\($\\|[ \t]\\)")
|
|
|
|
cmd))
|
2021-06-09 11:44:34 +02:00
|
|
|
(shell-process-cd (comint-substitute-in-file-name cmd)))
|
|
|
|
((and shell-has-auto-cd (file-directory-p cmd-subst-fn))
|
|
|
|
(shell-process-cd cmd-subst-fn)))
|
2003-06-12 22:20:49 +00:00
|
|
|
(setq start (progn (string-match shell-command-separator-regexp
|
|
|
|
str end)
|
|
|
|
;; skip again
|
2013-09-11 22:40:50 -07:00
|
|
|
(match-end 0))))))))
|
1993-10-22 02:53:24 +00:00
|
|
|
|
1999-07-20 04:16:51 +00:00
|
|
|
(defun shell-unquote-argument (string)
|
|
|
|
"Remove all kinds of shell quoting from STRING."
|
|
|
|
(save-match-data
|
2001-01-27 12:43:56 +00:00
|
|
|
(let ((idx 0) next inside
|
|
|
|
(quote-chars
|
|
|
|
(if (string-match shell-dumb-shell-regexp
|
|
|
|
(file-name-nondirectory
|
|
|
|
(car (process-command (get-buffer-process (current-buffer))))))
|
|
|
|
"['`\"]"
|
|
|
|
"[\\'`\"]")))
|
1999-07-20 04:16:51 +00:00
|
|
|
(while (and (< idx (length string))
|
2001-01-27 12:43:56 +00:00
|
|
|
(setq next (string-match quote-chars string next)))
|
1999-07-20 04:16:51 +00:00
|
|
|
(cond ((= (aref string next) ?\\)
|
|
|
|
(setq string (replace-match "" nil nil string))
|
|
|
|
(setq next (1+ next)))
|
|
|
|
((and inside (= (aref string next) inside))
|
|
|
|
(setq string (replace-match "" nil nil string))
|
|
|
|
(setq inside nil))
|
|
|
|
(inside
|
|
|
|
(setq next (1+ next)))
|
|
|
|
(t
|
|
|
|
(setq inside (aref string next))
|
|
|
|
(setq string (replace-match "" nil nil string)))))
|
|
|
|
string)))
|
|
|
|
|
2006-05-17 21:57:25 +00:00
|
|
|
;; popd [+n]
|
1990-11-05 10:06:02 +00:00
|
|
|
(defun shell-process-popd (arg)
|
1993-10-22 02:53:24 +00:00
|
|
|
(let ((num (or (shell-extract-num arg) 0)))
|
|
|
|
(cond ((and num (= num 0) shell-dirstack)
|
2010-11-06 13:08:58 +01:00
|
|
|
(shell-cd (shell-prefixed-directory-name (car shell-dirstack)))
|
1993-10-22 02:53:24 +00:00
|
|
|
(setq shell-dirstack (cdr shell-dirstack))
|
|
|
|
(shell-dirstack-message))
|
|
|
|
((and num (> num 0) (<= num (length shell-dirstack)))
|
|
|
|
(let* ((ds (cons nil shell-dirstack))
|
|
|
|
(cell (nthcdr (1- num) ds)))
|
|
|
|
(rplacd cell (cdr (cdr cell)))
|
|
|
|
(setq shell-dirstack (cdr ds))
|
|
|
|
(shell-dirstack-message)))
|
|
|
|
(t
|
1994-03-03 23:57:27 +00:00
|
|
|
(error "Couldn't popd")))))
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1994-01-06 17:02:00 +00:00
|
|
|
;; Return DIR prefixed with comint-file-name-prefix as appropriate.
|
1994-06-23 23:12:13 +00:00
|
|
|
(defun shell-prefixed-directory-name (dir)
|
|
|
|
(if (= (length comint-file-name-prefix) 0)
|
|
|
|
dir
|
|
|
|
(if (file-name-absolute-p dir)
|
|
|
|
;; The name is absolute, so prepend the prefix.
|
2022-02-15 18:13:04 +01:00
|
|
|
(concat comint-file-name-prefix (file-local-name dir))
|
1995-02-21 13:07:23 +00:00
|
|
|
;; For relative name we assume default-directory already has the prefix.
|
1994-06-23 23:12:13 +00:00
|
|
|
(expand-file-name dir))))
|
1994-01-06 17:02:00 +00:00
|
|
|
|
2006-05-17 21:57:25 +00:00
|
|
|
;; cd [dir]
|
1990-11-05 10:06:02 +00:00
|
|
|
(defun shell-process-cd (arg)
|
1994-01-06 17:02:00 +00:00
|
|
|
(let ((new-dir (cond ((zerop (length arg)) (concat comint-file-name-prefix
|
|
|
|
"~"))
|
1993-10-22 02:53:24 +00:00
|
|
|
((string-equal "-" arg) shell-last-dir)
|
1994-01-06 17:02:00 +00:00
|
|
|
(t (shell-prefixed-directory-name arg)))))
|
1993-10-22 02:53:24 +00:00
|
|
|
(setq shell-last-dir default-directory)
|
1995-02-21 13:07:23 +00:00
|
|
|
(shell-cd new-dir)
|
1993-10-22 02:53:24 +00:00
|
|
|
(shell-dirstack-message)))
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2006-05-17 21:57:25 +00:00
|
|
|
;; pushd [+n | dir]
|
1990-11-05 10:06:02 +00:00
|
|
|
(defun shell-process-pushd (arg)
|
1993-10-22 02:53:24 +00:00
|
|
|
(let ((num (shell-extract-num arg)))
|
|
|
|
(cond ((zerop (length arg))
|
|
|
|
;; no arg -- swap pwd and car of stack unless shell-pushd-tohome
|
|
|
|
(cond (shell-pushd-tohome
|
1994-01-06 17:02:00 +00:00
|
|
|
(shell-process-pushd (concat comint-file-name-prefix "~")))
|
1993-10-22 02:53:24 +00:00
|
|
|
(shell-dirstack
|
|
|
|
(let ((old default-directory))
|
1995-02-21 13:07:23 +00:00
|
|
|
(shell-cd (car shell-dirstack))
|
1996-02-03 13:38:32 +00:00
|
|
|
(setq shell-dirstack (cons old (cdr shell-dirstack)))
|
1993-10-22 02:53:24 +00:00
|
|
|
(shell-dirstack-message)))
|
|
|
|
(t
|
|
|
|
(message "Directory stack empty."))))
|
|
|
|
((numberp num)
|
|
|
|
;; pushd +n
|
|
|
|
(cond ((> num (length shell-dirstack))
|
|
|
|
(message "Directory stack not that deep."))
|
|
|
|
((= num 0)
|
2013-09-11 22:40:50 -07:00
|
|
|
(error "Couldn't cd"))
|
1993-10-22 02:53:24 +00:00
|
|
|
(shell-pushd-dextract
|
|
|
|
(let ((dir (nth (1- num) shell-dirstack)))
|
|
|
|
(shell-process-popd arg)
|
|
|
|
(shell-process-pushd default-directory)
|
1995-02-21 13:07:23 +00:00
|
|
|
(shell-cd dir)
|
1993-10-22 02:53:24 +00:00
|
|
|
(shell-dirstack-message)))
|
|
|
|
(t
|
|
|
|
(let* ((ds (cons default-directory shell-dirstack))
|
|
|
|
(dslen (length ds))
|
|
|
|
(front (nthcdr num ds))
|
|
|
|
(back (reverse (nthcdr (- dslen num) (reverse ds))))
|
|
|
|
(new-ds (append front back)))
|
1995-02-21 13:07:23 +00:00
|
|
|
(shell-cd (car new-ds))
|
1993-10-22 02:53:24 +00:00
|
|
|
(setq shell-dirstack (cdr new-ds))
|
|
|
|
(shell-dirstack-message)))))
|
|
|
|
(t
|
|
|
|
;; pushd <dir>
|
|
|
|
(let ((old-wd default-directory))
|
1995-02-21 13:07:23 +00:00
|
|
|
(shell-cd (shell-prefixed-directory-name arg))
|
1993-10-22 02:53:24 +00:00
|
|
|
(if (or (null shell-pushd-dunique)
|
|
|
|
(not (member old-wd shell-dirstack)))
|
|
|
|
(setq shell-dirstack (cons old-wd shell-dirstack)))
|
|
|
|
(shell-dirstack-message))))))
|
1990-11-05 10:06:02 +00:00
|
|
|
|
|
|
|
;; If STR is of the form +n, for n>0, return n. Otherwise, nil.
|
|
|
|
(defun shell-extract-num (str)
|
|
|
|
(and (string-match "^\\+[1-9][0-9]*$" str)
|
2005-05-16 11:34:49 +00:00
|
|
|
(string-to-number str)))
|
1990-11-05 10:06:02 +00:00
|
|
|
|
1995-02-21 13:07:23 +00:00
|
|
|
(defun shell-cd (dir)
|
|
|
|
"Do normal `cd' to DIR, and set `list-buffers-directory'."
|
2006-05-17 21:57:25 +00:00
|
|
|
(cd dir)
|
2023-06-26 22:32:07 -06:00
|
|
|
(if shell-dirtrack-mode
|
2006-05-17 21:57:25 +00:00
|
|
|
(setq list-buffers-directory default-directory)))
|
1990-11-05 10:06:02 +00:00
|
|
|
|
|
|
|
(defun shell-resync-dirs ()
|
|
|
|
"Resync the buffer's idea of the current directory stack.
|
2001-01-28 03:43:35 +00:00
|
|
|
This command queries the shell with the command bound to
|
1993-04-29 14:23:22 +00:00
|
|
|
`shell-dirstack-query' (default \"dirs\"), reads the next
|
2022-03-17 14:50:05 +01:00
|
|
|
line output and parses it to form the new directory stack."
|
1990-11-05 10:06:02 +00:00
|
|
|
(interactive)
|
2022-03-17 14:50:05 +01:00
|
|
|
(let* ((dls (car
|
|
|
|
(last
|
|
|
|
(string-lines
|
|
|
|
(string-chop-newline
|
|
|
|
(shell-eval-command (concat shell-dirstack-query "\n")))))))
|
|
|
|
(dlsl nil)
|
|
|
|
(pos 0)
|
|
|
|
(ds nil))
|
2022-12-10 14:55:01 +02:00
|
|
|
(setq dls (string-trim-right dls "[ ]+"))
|
2022-03-17 14:50:05 +01:00
|
|
|
;; Split the dirlist into whitespace and non-whitespace chunks.
|
|
|
|
;; dlsl will be a reversed list of tokens.
|
|
|
|
(while (string-match "\\(\\S-+\\|\\s-+\\)" dls pos)
|
|
|
|
(push (match-string 1 dls) dlsl)
|
|
|
|
(setq pos (match-end 1)))
|
|
|
|
|
|
|
|
;; Prepend trailing entries until they form an existing directory,
|
|
|
|
;; whitespace and all. Discard the next whitespace and repeat.
|
|
|
|
(while dlsl
|
|
|
|
(let ((newelt "")
|
|
|
|
tem1 tem2)
|
2024-07-12 09:58:53 +03:00
|
|
|
(while (and dlsl newelt)
|
2022-03-17 14:50:05 +01:00
|
|
|
;; We need tem1 because we don't want to prepend
|
|
|
|
;; `comint-file-name-prefix' repeatedly into newelt via tem2.
|
|
|
|
(setq tem1 (pop dlsl)
|
|
|
|
tem2 (concat comint-file-name-prefix tem1 newelt))
|
|
|
|
(cond ((file-directory-p tem2)
|
|
|
|
(push tem2 ds)
|
|
|
|
(when (string= " " (car dlsl))
|
|
|
|
(pop dlsl))
|
|
|
|
(setq newelt nil))
|
|
|
|
(t
|
|
|
|
(setq newelt (concat tem1 newelt)))))))
|
|
|
|
|
|
|
|
(with-demoted-errors "Couldn't cd: %s"
|
|
|
|
(shell-cd (car ds))
|
|
|
|
(setq shell-dirstack (cdr ds)
|
|
|
|
shell-last-dir (car shell-dirstack))
|
|
|
|
(shell-dirstack-message))))
|
1990-11-05 10:06:02 +00:00
|
|
|
|
2006-05-17 21:57:25 +00:00
|
|
|
;; For your typing convenience:
|
1993-04-23 06:51:44 +00:00
|
|
|
(defalias 'dirs 'shell-resync-dirs)
|
1990-11-05 10:06:02 +00:00
|
|
|
|
|
|
|
|
2006-05-17 21:57:25 +00:00
|
|
|
;; Show the current dirstack on the message line.
|
|
|
|
;; Pretty up dirs a bit by changing "/usr/jqr/foo" to "~/foo".
|
|
|
|
;; (This isn't necessary if the dirlisting is generated with a simple "dirs".)
|
|
|
|
;; All the commands that mung the buffer's dirstack finish by calling
|
|
|
|
;; this guy.
|
1990-11-05 10:06:02 +00:00
|
|
|
(defun shell-dirstack-message ()
|
1999-01-14 10:31:31 +00:00
|
|
|
(when shell-dirtrack-verbose
|
|
|
|
(let* ((msg "")
|
|
|
|
(ds (cons default-directory shell-dirstack))
|
|
|
|
(home (expand-file-name (concat comint-file-name-prefix "~/")))
|
|
|
|
(homelen (length home)))
|
|
|
|
(while ds
|
|
|
|
(let ((dir (car ds)))
|
|
|
|
(and (>= (length dir) homelen)
|
|
|
|
(string= home (substring dir 0 homelen))
|
|
|
|
(setq dir (concat "~/" (substring dir homelen))))
|
|
|
|
;; Strip off comint-file-name-prefix if present.
|
|
|
|
(and comint-file-name-prefix
|
|
|
|
(>= (length dir) (length comint-file-name-prefix))
|
|
|
|
(string= comint-file-name-prefix
|
|
|
|
(substring dir 0 (length comint-file-name-prefix)))
|
|
|
|
(setq dir (substring dir (length comint-file-name-prefix)))
|
|
|
|
(setcar ds dir))
|
|
|
|
(setq msg (concat msg (directory-file-name dir) " "))
|
|
|
|
(setq ds (cdr ds))))
|
|
|
|
(message "%s" msg))))
|
2001-01-28 03:43:35 +00:00
|
|
|
|
1997-08-22 23:37:38 +00:00
|
|
|
;; This was mostly copied from shell-resync-dirs.
|
|
|
|
(defun shell-snarf-envar (var)
|
|
|
|
"Return as a string the shell's value of environment variable VAR."
|
|
|
|
(let* ((cmd (format "printenv '%s'\n" var))
|
|
|
|
(proc (get-buffer-process (current-buffer)))
|
|
|
|
(pmark (process-mark proc)))
|
|
|
|
(goto-char pmark)
|
|
|
|
(insert cmd)
|
|
|
|
(sit-for 0) ; force redisplay
|
|
|
|
(comint-send-string proc cmd)
|
|
|
|
(set-marker pmark (point))
|
|
|
|
(let ((pt (point))) ; wait for 1 line
|
|
|
|
;; This extra newline prevents the user's pending input from spoofing us.
|
|
|
|
(insert "\n") (backward-char 1)
|
|
|
|
(while (not (looking-at ".+\n"))
|
|
|
|
(accept-process-output proc)
|
|
|
|
(goto-char pt)))
|
|
|
|
(goto-char pmark) (delete-char 1) ; remove the extra newline
|
|
|
|
(buffer-substring (match-beginning 0) (1- (match-end 0)))))
|
|
|
|
|
|
|
|
(defun shell-copy-environment-variable (variable)
|
|
|
|
"Copy the environment variable VARIABLE from the subshell to Emacs.
|
|
|
|
This command reads the value of the specified environment variable
|
|
|
|
in the shell, and sets the same environment variable in Emacs
|
1998-06-28 22:43:25 +00:00
|
|
|
\(what `getenv' in Emacs would return) to that value.
|
1997-08-22 23:37:38 +00:00
|
|
|
That value will affect any new subprocesses that you subsequently start
|
|
|
|
from Emacs."
|
|
|
|
(interactive (list (read-envvar-name "\
|
|
|
|
Copy Shell environment variable to Emacs: ")))
|
|
|
|
(setenv variable (shell-snarf-envar variable)))
|
2001-01-28 03:43:35 +00:00
|
|
|
|
1993-10-22 02:53:24 +00:00
|
|
|
(defun shell-forward-command (&optional arg)
|
|
|
|
"Move forward across ARG shell command(s). Does not cross lines.
|
|
|
|
See `shell-command-regexp'."
|
|
|
|
(interactive "p")
|
2015-06-23 09:19:36 +08:00
|
|
|
(let ((limit (line-end-position))
|
|
|
|
(pt (point)))
|
|
|
|
(re-search-forward (concat shell-command-regexp "\\([;&|][\t ]*\\)+")
|
|
|
|
limit 'move arg)
|
|
|
|
(and (/= pt (point))
|
|
|
|
(skip-syntax-backward " " pt))))
|
1993-10-22 02:53:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
(defun shell-backward-command (&optional arg)
|
|
|
|
"Move backward across ARG shell command(s). Does not cross lines.
|
|
|
|
See `shell-command-regexp'."
|
|
|
|
(interactive "p")
|
|
|
|
(let ((limit (save-excursion (comint-bol nil) (point))))
|
2000-08-07 14:51:48 +00:00
|
|
|
(when (> limit (point))
|
|
|
|
(setq limit (line-beginning-position)))
|
1993-12-24 05:42:58 +00:00
|
|
|
(skip-syntax-backward " " limit)
|
2015-06-23 09:19:36 +08:00
|
|
|
(let ((pt (point)))
|
|
|
|
(if (re-search-backward
|
|
|
|
(format "[;&|]+[\t ]*\\(%s\\)" shell-command-regexp) limit 'move arg)
|
|
|
|
(progn (goto-char (match-beginning 1))
|
|
|
|
(skip-chars-forward ";&|")))
|
|
|
|
(and (/= pt (point))
|
|
|
|
(skip-syntax-forward " " pt)))))
|
1993-10-22 02:53:24 +00:00
|
|
|
|
|
|
|
(defun shell-dynamic-complete-command ()
|
|
|
|
"Dynamically complete the command at point.
|
|
|
|
This function is similar to `comint-dynamic-complete-filename', except that it
|
2013-12-27 21:58:21 +01:00
|
|
|
searches `exec-path' (minus trailing `exec-directory') for completion
|
1993-10-22 02:53:24 +00:00
|
|
|
candidates. Note that this may not be the same as the shell's idea of the
|
|
|
|
path.
|
|
|
|
|
2013-12-27 21:58:21 +01:00
|
|
|
Completion is dependent on the value of `shell-completion-execonly',
|
|
|
|
`shell-completion-fignore', plus those that affect file completion. See Info
|
|
|
|
node `Shell Options'.
|
1994-03-03 23:37:27 +00:00
|
|
|
|
|
|
|
Returns t if successful."
|
1993-10-22 02:53:24 +00:00
|
|
|
(interactive)
|
2011-04-20 19:31:06 -03:00
|
|
|
(let ((data (shell-command-completion)))
|
|
|
|
(if data
|
Do not call to `selected-window' where it is assumed by default.
Affected functions are `window-minibuffer-p', `window-dedicated-p',
`window-hscroll', `window-width', `window-height', `window-buffer',
`window-frame', `window-start', `window-point', `next-window'
and `window-display-table'.
* abbrev.el (abbrev--default-expand):
* bs.el (bs--show-with-configuration):
* buff-menu.el (Buffer-menu-mouse-select):
* calc/calc.el (calc):
* calendar/calendar.el (calendar-generate-window):
* calendar/diary-lib.el (diary-simple-display, diary-show-all-entries)
(diary-make-entry):
* comint.el (send-invisible, comint-dynamic-complete-filename)
(comint-dynamic-simple-complete, comint-dynamic-list-completions):
* completion.el (complete):
* dabbrev.el (dabbrev-expand, dabbrev--make-friend-buffer-list):
* disp-table.el (describe-current-display-table):
* doc-view.el (doc-view-insert-image):
* ebuff-menu.el (Electric-buffer-menu-mouse-select):
* ehelp.el (with-electric-help):
* emacs-lisp/easy-mmode.el (easy-mmode-define-navigation):
* emacs-lisp/edebug.el (edebug-two-window-p, edebug-pop-to-buffer):
* emacs-lisp/helper.el (Helper-help-scroller):
* emulation/cua-base.el (cua--post-command-handler-1):
* eshell/esh-mode.el (eshell-output-filter):
* ffap.el (ffap-gnus-wrapper):
* help-macro.el (make-help-screen):
* hilit-chg.el (highlight-compare-buffers):
* hippie-exp.el (hippie-expand, try-expand-dabbrev-visible):
* hl-line.el (global-hl-line-highlight):
* icomplete.el (icomplete-simple-completing-p):
* isearch.el (isearch-done):
* jit-lock.el (jit-lock-stealth-fontify):
* mail/rmailsum.el (rmail-summary-scroll-msg-up):
* lisp/mouse-drag.el (mouse-drag-should-do-col-scrolling):
* mpc.el (mpc-tagbrowser, mpc):
* net/rcirc.el (rcirc-any-buffer):
* play/gomoku.el (gomoku-max-width, gomoku-max-height):
* play/landmark.el (landmark-max-width, landmark-max-height):
* play/zone.el (zone):
* progmodes/compile.el (compilation-goto-locus):
* progmodes/ebrowse.el (ebrowse-view/find-file-and-search-pattern):
* progmodes/etags.el (find-tag-other-window):
* progmodes/fortran.el (fortran-column-ruler):
* progmodes/gdb-mi.el (gdb-mouse-toggle-breakpoint-fringe):
* progmodes/verilog-mode.el (verilog-point-text):
* reposition.el (reposition-window):
* rot13.el (toggle-rot13-mode):
* server.el (server-switch-buffer):
* shell.el (shell-dynamic-complete-command)
(shell-dynamic-complete-environment-variable):
* simple.el (insert-buffer, set-selective-display)
(delete-completion-window):
* speedbar.el (speedbar-timer-fn, speedbar-center-buffer-smartly)
(speedbar-recenter):
* startup.el (fancy-splash-head):
* textmodes/ispell.el (ispell-command-loop):
* textmodes/makeinfo.el (makeinfo-compilation-sentinel-region):
* tutorial.el (help-with-tutorial):
* vc/add-log.el (add-change-log-entry):
* vc/compare-w.el (compare-windows):
* vc/ediff-help.el (ediff-indent-help-message):
* vc/ediff-util.el (ediff-setup-control-buffer, ediff-position-region):
* vc/ediff-wind.el (ediff-skip-unsuitable-frames)
(ediff-setup-control-frame):
* vc/emerge.el (emerge-position-region):
* vc/pcvs-util.el (cvs-bury-buffer):
* window.el (walk-windows, mouse-autoselect-window-select):
* winner.el (winner-set-conf, winner-undo): Related users changed.
2013-08-05 18:26:57 +04:00
|
|
|
(prog2 (unless (window-minibuffer-p)
|
2011-04-20 19:31:06 -03:00
|
|
|
(message "Completing command name..."))
|
2021-08-19 18:01:06 +02:00
|
|
|
(completion-in-region (nth 0 data) (nth 1 data) (nth 2 data))))))
|
2011-04-20 19:31:06 -03:00
|
|
|
|
|
|
|
(defun shell-command-completion ()
|
|
|
|
"Return the completion data for the command at point, if any."
|
1994-03-03 23:37:27 +00:00
|
|
|
(let ((filename (comint-match-partial-filename)))
|
|
|
|
(if (and filename
|
|
|
|
(save-match-data (not (string-match "[~/]" filename)))
|
|
|
|
(eq (match-beginning 0)
|
|
|
|
(save-excursion (shell-backward-command 1) (point))))
|
2011-04-20 19:31:06 -03:00
|
|
|
(shell--command-completion-data))))
|
1994-03-03 23:37:27 +00:00
|
|
|
|
2011-04-20 19:31:06 -03:00
|
|
|
(defun shell--command-completion-data ()
|
|
|
|
"Return the completion data for the command at point."
|
1994-03-24 07:51:27 +00:00
|
|
|
(let* ((filename (or (comint-match-partial-filename) ""))
|
2011-04-20 19:31:06 -03:00
|
|
|
(start (if (zerop (length filename)) (point) (match-beginning 0)))
|
|
|
|
(end (if (zerop (length filename)) (point) (match-end 0)))
|
2003-12-29 19:13:28 +00:00
|
|
|
(filenondir (file-name-nondirectory filename))
|
2018-06-20 12:13:56 +02:00
|
|
|
(path-dirs
|
|
|
|
;; Ignore `exec-directory', the last entry in `exec-path'.
|
|
|
|
(append (cdr (reverse (exec-path)))
|
|
|
|
(if (and (memq system-type '(windows-nt ms-dos))
|
|
|
|
(not (file-remote-p default-directory)))
|
|
|
|
'("."))))
|
1993-10-22 02:53:24 +00:00
|
|
|
(cwd (file-name-as-directory (expand-file-name default-directory)))
|
|
|
|
(ignored-extensions
|
1994-03-10 18:54:44 +00:00
|
|
|
(and comint-completion-fignore
|
2020-09-30 16:18:50 +02:00
|
|
|
(mapconcat (lambda (x) (concat (regexp-quote x) "\\'"))
|
1994-03-10 18:54:44 +00:00
|
|
|
comint-completion-fignore "\\|")))
|
2005-06-16 16:10:43 +00:00
|
|
|
(dir "") (comps-in-dir ())
|
2003-12-29 19:13:28 +00:00
|
|
|
(file "") (abs-file-name "") (completions ()))
|
|
|
|
;; Go thru each dir in the search path, finding completions.
|
|
|
|
(while path-dirs
|
|
|
|
(setq dir (file-name-as-directory (comint-directory (or (car path-dirs) ".")))
|
|
|
|
comps-in-dir (and (file-accessible-directory-p dir)
|
2023-01-25 18:44:47 +08:00
|
|
|
(condition-case nil
|
|
|
|
(file-name-all-completions filenondir dir)
|
|
|
|
;; Systems such as Android sometimes
|
|
|
|
;; put inaccessible directories in
|
|
|
|
;; PATH.
|
|
|
|
(permission-denied nil))))
|
1993-10-22 02:53:24 +00:00
|
|
|
;; Go thru each completion found, to see whether it should be used.
|
2003-12-29 19:13:28 +00:00
|
|
|
(while comps-in-dir
|
|
|
|
(setq file (car comps-in-dir)
|
|
|
|
abs-file-name (concat dir file))
|
1993-10-22 02:53:24 +00:00
|
|
|
(if (and (not (member file completions))
|
1994-04-14 19:19:30 +00:00
|
|
|
(not (and ignored-extensions
|
|
|
|
(string-match ignored-extensions file)))
|
2003-12-29 19:13:28 +00:00
|
|
|
(or (string-equal dir cwd)
|
|
|
|
(not (file-directory-p abs-file-name)))
|
1993-10-22 02:53:24 +00:00
|
|
|
(or (null shell-completion-execonly)
|
2003-12-29 19:13:28 +00:00
|
|
|
(file-executable-p abs-file-name)))
|
1993-10-22 02:53:24 +00:00
|
|
|
(setq completions (cons file completions)))
|
2003-12-29 19:13:28 +00:00
|
|
|
(setq comps-in-dir (cdr comps-in-dir)))
|
|
|
|
(setq path-dirs (cdr path-dirs)))
|
1993-10-22 02:53:24 +00:00
|
|
|
;; OK, we've got a list of completions.
|
2011-04-20 19:31:06 -03:00
|
|
|
(list
|
|
|
|
start end
|
|
|
|
(lambda (string pred action)
|
Use string-search instead of string-match[-p]
`string-search` is easier to understand, less error-prone, much
faster, does not pollute the regexp cache, and does not mutate global
state. Use it where applicable and obviously safe (erring on the
conservative side).
* admin/authors.el (authors-canonical-file-name)
(authors-scan-change-log):
* lisp/apropos.el (apropos-command)
(apropos-documentation-property, apropos-symbols-internal):
* lisp/arc-mode.el (archive-arc-summarize)
(archive-zoo-summarize):
* lisp/calc/calc-aent.el (math-read-factor):
* lisp/calc/calc-ext.el (math-read-big-expr)
(math-format-nice-expr, math-format-number-fancy):
* lisp/calc/calc-forms.el (math-read-angle-brackets):
* lisp/calc/calc-graph.el (calc-graph-set-range):
* lisp/calc/calc-keypd.el (calc-keypad-press):
* lisp/calc/calc-lang.el (tex, latex, math-read-big-rec):
* lisp/calc/calc-prog.el (calc-fix-token-name)
(calc-user-define-permanent, math-define-exp):
* lisp/calc/calc.el (calc-record, calcDigit-key)
(calc-count-lines):
* lisp/calc/calcalg2.el (calc-solve-for, calc-poly-roots)
(math-do-integral):
* lisp/calc/calcalg3.el (calc-find-root, calc-find-minimum)
(calc-get-fit-variables):
* lisp/cedet/ede/speedbar.el (ede-tag-expand):
* lisp/cedet/semantic/java.el (semantic-java-expand-tag):
* lisp/cedet/semantic/sb.el (semantic-sb-show-extra)
(semantic-sb-expand-group):
* lisp/cedet/semantic/wisent/python.el
(semantic-python-instance-variable-p):
* lisp/cus-edit.el (get):
* lisp/descr-text.el (describe-text-sexp):
* lisp/dired-aux.el (dired-compress-file):
* lisp/dired-x.el (dired-make-relative-symlink):
* lisp/dired.el (dired-glob-regexp):
* lisp/dos-fns.el (dos-convert-standard-filename, dos-8+3-filename):
* lisp/edmacro.el (edmacro-format-keys):
* lisp/emacs-lisp/eieio-opt.el (eieio-sb-expand):
* lisp/emacs-lisp/eieio-speedbar.el (eieio-speedbar-object-expand):
* lisp/emacs-lisp/lisp-mnt.el (lm-keywords-list):
* lisp/emacs-lisp/warnings.el (display-warning):
* lisp/emulation/viper-ex.el (viper-ex-read-file-name)
(ex-print-display-lines):
* lisp/env.el (read-envvar-name, setenv):
* lisp/epa-mail.el (epa-mail-encrypt):
* lisp/epg.el (epg--start):
* lisp/erc/erc-backend.el (erc-parse-server-response):
* lisp/erc/erc-dcc.el (erc-dcc-member):
* lisp/erc/erc-speedbar.el (erc-speedbar-expand-server)
(erc-speedbar-expand-channel, erc-speedbar-expand-user):
* lisp/erc/erc.el (erc-send-input):
* lisp/eshell/em-glob.el (eshell-glob-entries):
* lisp/eshell/esh-proc.el (eshell-needs-pipe-p):
* lisp/eshell/esh-util.el (eshell-convert):
* lisp/eshell/esh-var.el (eshell-envvar-names):
* lisp/faces.el (x-resolve-font-name):
* lisp/ffap.el (ffap-file-at-point):
* lisp/files.el (wildcard-to-regexp, shell-quote-wildcard-pattern):
* lisp/forms.el (forms--update):
* lisp/frameset.el (frameset-filter-unshelve-param):
* lisp/gnus/gnus-art.el (article-decode-charset):
* lisp/gnus/gnus-kill.el (gnus-kill-parse-rn-kill-file):
* lisp/gnus/gnus-mlspl.el (gnus-group-split-fancy):
* lisp/gnus/gnus-msg.el (gnus-summary-resend-message-insert-gcc)
(gnus-inews-insert-gcc):
* lisp/gnus/gnus-rfc1843.el (rfc1843-decode-article-body):
* lisp/gnus/gnus-search.el (gnus-search-indexed-parse-output)
(gnus-search--complete-key-data):
* lisp/gnus/gnus-spec.el (gnus-parse-simple-format):
* lisp/gnus/gnus-sum.el (gnus-summary-refer-article):
* lisp/gnus/gnus-util.el (gnus-extract-address-components)
(gnus-newsgroup-directory-form):
* lisp/gnus/gnus-uu.el (gnus-uu-grab-view):
* lisp/gnus/gnus.el (gnus-group-native-p, gnus-short-group-name):
* lisp/gnus/message.el (message-check-news-header-syntax)
(message-make-message-id, message-user-mail-address)
(message-make-fqdn, message-get-reply-headers, message-followup):
* lisp/gnus/mm-decode.el (mm-dissect-buffer):
* lisp/gnus/nnheader.el (nnheader-insert):
* lisp/gnus/nnimap.el (nnimap-process-quirk)
(nnimap-imap-ranges-to-gnus-ranges):
* lisp/gnus/nnmaildir.el (nnmaildir--ensure-suffix):
* lisp/gnus/nnmairix.el (nnmairix-determine-original-group-from-path):
* lisp/gnus/nnrss.el (nnrss-match-macro):
* lisp/gnus/nntp.el (nntp-find-group-and-number):
* lisp/help-fns.el (help--symbol-completion-table-affixation):
* lisp/help.el (help-function-arglist):
* lisp/hippie-exp.el (he-concat-directory-file-name):
* lisp/htmlfontify.el (hfy-relstub):
* lisp/ido.el (ido-make-prompt, ido-complete, ido-copy-current-word)
(ido-exhibit):
* lisp/image/image-converter.el (image-convert-p):
* lisp/info-xref.el (info-xref-docstrings):
* lisp/info.el (Info-toc-build, Info-follow-reference)
(Info-backward-node, Info-finder-find-node)
(Info-speedbar-expand-node):
* lisp/international/mule-diag.el (print-fontset-element):
* lisp/language/korea-util.el (default-korean-keyboard):
* lisp/linum.el (linum-after-change):
* lisp/mail/ietf-drums.el (ietf-drums-parse-address):
* lisp/mail/mail-utils.el (mail-dont-reply-to):
* lisp/mail/rfc2047.el (rfc2047-encode-1, rfc2047-decode-string):
* lisp/mail/rfc2231.el (rfc2231-parse-string):
* lisp/mail/rmailkwd.el (rmail-set-label):
* lisp/mail/rmailsum.el (rmail-header-summary):
* lisp/mail/smtpmail.el (smtpmail-maybe-append-domain)
(smtpmail-user-mail-address):
* lisp/mail/uce.el (uce-reply-to-uce):
* lisp/man.el (Man-default-man-entry):
* lisp/mh-e/mh-alias.el (mh-alias-gecos-name)
(mh-alias-minibuffer-confirm-address):
* lisp/mh-e/mh-comp.el (mh-forwarded-letter-subject):
* lisp/mh-e/mh-speed.el (mh-speed-parse-flists-output):
* lisp/mh-e/mh-utils.el (mh-collect-folder-names-filter)
(mh-folder-completion-function):
* lisp/minibuffer.el (completion--make-envvar-table)
(completion-file-name-table, completion-flex-try-completion)
(completion-flex-all-completions):
* lisp/mpc.el (mpc--proc-quote-string, mpc-cmd-special-tag-p)
(mpc-constraints-tag-lookup):
* lisp/net/ange-ftp.el (ange-ftp-send-cmd)
(ange-ftp-allow-child-lookup):
* lisp/net/mailcap.el (mailcap-mime-types):
* lisp/net/mairix.el (mairix-search-thread-this-article):
* lisp/net/pop3.el (pop3-open-server):
* lisp/net/soap-client.el (soap-decode-xs-complex-type):
* lisp/net/socks.el (socks-filter):
* lisp/nxml/nxml-outln.el (nxml-highlighted-qname):
* lisp/nxml/rng-cmpct.el (rng-c-expand-name, rng-c-expand-datatype):
* lisp/nxml/rng-uri.el (rng-uri-file-name-1):
* lisp/obsolete/complete.el (partial-completion-mode)
(PC-do-completion):
* lisp/obsolete/longlines.el (longlines-encode-string):
* lisp/obsolete/nnir.el (nnir-compose-result):
* lisp/obsolete/terminal.el (te-quote-arg-for-sh):
* lisp/obsolete/tpu-edt.el (tpu-check-search-case):
* lisp/obsolete/url-ns.el (isPlainHostName):
* lisp/pcmpl-unix.el (pcomplete/scp):
* lisp/play/dunnet.el (dun-listify-string2, dun-get-path)
(dun-unix-parse, dun-doassign, dun-cat, dun-batch-unix-interface):
* lisp/progmodes/ebnf2ps.el: (ebnf-eps-header-footer-comment):
* lisp/progmodes/gdb-mi.el (gdb-var-delete)
(gdb-speedbar-expand-node, gdbmi-bnf-incomplete-record-result):
* lisp/progmodes/gud.el (gud-find-expr):
* lisp/progmodes/idlw-help.el (idlwave-do-context-help1):
* lisp/progmodes/idlw-shell.el (idlwave-shell-mode)
(idlwave-shell-filter-hidden-output, idlwave-shell-filter):
* lisp/progmodes/idlwave.el (idlwave-skip-label-or-case)
(idlwave-routine-info):
* lisp/progmodes/octave.el (inferior-octave-completion-at-point):
* lisp/progmodes/sh-script.el (sh-add-completer):
* lisp/progmodes/sql.el (defun):
* lisp/progmodes/xscheme.el (xscheme-process-filter):
* lisp/replace.el (query-replace-compile-replacement)
(map-query-replace-regexp):
* lisp/shell.el (shell--command-completion-data)
(shell-environment-variable-completion):
* lisp/simple.el (display-message-or-buffer):
* lisp/speedbar.el (speedbar-dired, speedbar-tag-file)
(speedbar-tag-expand):
* lisp/subr.el (split-string-and-unquote):
* lisp/tar-mode.el (tar-extract):
* lisp/term.el (term-command-hook, serial-read-name):
* lisp/textmodes/bibtex.el (bibtex-print-help-message):
* lisp/textmodes/ispell.el (ispell-lookup-words, ispell-filter)
(ispell-parse-output, ispell-buffer-local-parsing):
* lisp/textmodes/reftex-cite.el (reftex-do-citation):
* lisp/textmodes/reftex-parse.el (reftex-notice-new):
* lisp/textmodes/reftex-ref.el (reftex-show-entry):
* lisp/textmodes/reftex.el (reftex-compile-variables):
* lisp/textmodes/tex-mode.el (tex-send-command)
(tex-start-tex, tex-append):
* lisp/thingatpt.el (thing-at-point-url-at-point):
* lisp/tmm.el (tmm-add-one-shortcut):
* lisp/transient.el (transient-format-key):
* lisp/url/url-auth.el (url-basic-auth)
(url-digest-auth-directory-id-assoc):
* lisp/url/url-news.el (url-news):
* lisp/url/url-util.el (url-parse-query-string):
* lisp/vc/vc-cvs.el (vc-cvs-parse-entry):
* lisp/wid-browse.el (widget-browse-sexp):
* lisp/woman.el (woman-parse-colon-path, woman-mini-help)
(WoMan-getpage-in-background, woman-negative-vertical-space):
* lisp/xml.el:
* test/lisp/emacs-lisp/check-declare-tests.el
(check-declare-tests-warn):
* test/lisp/files-tests.el
(files-tests-file-name-non-special-dired-compress-handler):
* test/lisp/net/network-stream-tests.el (server-process-filter):
* test/src/coding-tests.el (ert-test-unibyte-buffer-dos-eol-decode):
Use `string-search` instead of `string-match` and `string-match-p`.
2021-08-09 11:20:00 +02:00
|
|
|
(if (string-search "/" string)
|
2011-05-23 23:45:50 -03:00
|
|
|
(completion-file-name-table string pred action)
|
|
|
|
(complete-with-action action completions string pred)))
|
|
|
|
:exit-function
|
|
|
|
(lambda (_string finished)
|
|
|
|
(when (memq finished '(sole finished))
|
|
|
|
(if (looking-at " ")
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
(insert " ")))))))
|
2011-04-20 19:31:06 -03:00
|
|
|
|
|
|
|
;; (defun shell-dynamic-complete-as-command ()
|
|
|
|
;; "Dynamically complete at point as a command.
|
|
|
|
;; See `shell-dynamic-complete-filename'. Returns t if successful."
|
|
|
|
;; (apply #'completion-in-region shell--command-completion-data))
|
1994-03-03 23:37:27 +00:00
|
|
|
|
2008-04-03 05:13:15 +00:00
|
|
|
(defun shell-dynamic-complete-filename ()
|
|
|
|
"Dynamically complete the filename at point.
|
|
|
|
This completes only if point is at a suitable position for a
|
|
|
|
filename argument."
|
|
|
|
(interactive)
|
2011-04-20 19:31:06 -03:00
|
|
|
(let ((data (shell-filename-completion)))
|
|
|
|
(if data (apply #'completion-in-region data))))
|
|
|
|
|
|
|
|
(defun shell-filename-completion ()
|
|
|
|
"Return the completion data for file name at point, if any."
|
2008-04-03 05:13:15 +00:00
|
|
|
(let ((opoint (point))
|
|
|
|
(beg (comint-line-beginning-position)))
|
|
|
|
(when (save-excursion
|
|
|
|
(goto-char (if (re-search-backward "[;|&]" beg t)
|
|
|
|
(match-end 0)
|
|
|
|
beg))
|
|
|
|
(re-search-forward "[^ \t][ \t]" opoint t))
|
2011-04-20 19:31:06 -03:00
|
|
|
(comint-filename-completion))))
|
1994-03-03 23:37:27 +00:00
|
|
|
|
|
|
|
(defun shell-match-partial-variable ()
|
1996-06-04 15:27:52 +00:00
|
|
|
"Return the shell variable at point, or nil if none is found."
|
1994-03-03 23:37:27 +00:00
|
|
|
(save-excursion
|
2011-04-20 19:31:06 -03:00
|
|
|
(if (re-search-backward "[^A-Za-z0-9_{(]" nil 'move)
|
|
|
|
(or (looking-at "\\$") (forward-char 1)))
|
|
|
|
(if (or (eolp) (looking-at "[^A-Za-z0-9_{($]"))
|
|
|
|
nil
|
|
|
|
(looking-at "\\$?[{(]?[A-Za-z0-9_]*[})]?")
|
|
|
|
(buffer-substring (match-beginning 0) (match-end 0)))))
|
1991-05-08 07:47:45 +00:00
|
|
|
|
1994-03-03 23:37:27 +00:00
|
|
|
(defun shell-dynamic-complete-environment-variable ()
|
|
|
|
"Dynamically complete the environment variable at point.
|
|
|
|
Completes if after a variable, i.e., if it starts with a \"$\".
|
|
|
|
|
|
|
|
This function is similar to `comint-dynamic-complete-filename', except that it
|
|
|
|
searches `process-environment' for completion candidates. Note that this may
|
|
|
|
not be the same as the interpreter's idea of variable names. The main problem
|
|
|
|
with this type of completion is that `process-environment' is the environment
|
|
|
|
which Emacs started with. Emacs does not track changes to the environment made
|
|
|
|
by the interpreter. Perhaps it would be more accurate if this function was
|
|
|
|
called `shell-dynamic-complete-process-environment-variable'.
|
|
|
|
|
|
|
|
Returns non-nil if successful."
|
|
|
|
(interactive)
|
2011-04-20 19:31:06 -03:00
|
|
|
(let ((data (shell-environment-variable-completion)))
|
|
|
|
(if data
|
Do not call to `selected-window' where it is assumed by default.
Affected functions are `window-minibuffer-p', `window-dedicated-p',
`window-hscroll', `window-width', `window-height', `window-buffer',
`window-frame', `window-start', `window-point', `next-window'
and `window-display-table'.
* abbrev.el (abbrev--default-expand):
* bs.el (bs--show-with-configuration):
* buff-menu.el (Buffer-menu-mouse-select):
* calc/calc.el (calc):
* calendar/calendar.el (calendar-generate-window):
* calendar/diary-lib.el (diary-simple-display, diary-show-all-entries)
(diary-make-entry):
* comint.el (send-invisible, comint-dynamic-complete-filename)
(comint-dynamic-simple-complete, comint-dynamic-list-completions):
* completion.el (complete):
* dabbrev.el (dabbrev-expand, dabbrev--make-friend-buffer-list):
* disp-table.el (describe-current-display-table):
* doc-view.el (doc-view-insert-image):
* ebuff-menu.el (Electric-buffer-menu-mouse-select):
* ehelp.el (with-electric-help):
* emacs-lisp/easy-mmode.el (easy-mmode-define-navigation):
* emacs-lisp/edebug.el (edebug-two-window-p, edebug-pop-to-buffer):
* emacs-lisp/helper.el (Helper-help-scroller):
* emulation/cua-base.el (cua--post-command-handler-1):
* eshell/esh-mode.el (eshell-output-filter):
* ffap.el (ffap-gnus-wrapper):
* help-macro.el (make-help-screen):
* hilit-chg.el (highlight-compare-buffers):
* hippie-exp.el (hippie-expand, try-expand-dabbrev-visible):
* hl-line.el (global-hl-line-highlight):
* icomplete.el (icomplete-simple-completing-p):
* isearch.el (isearch-done):
* jit-lock.el (jit-lock-stealth-fontify):
* mail/rmailsum.el (rmail-summary-scroll-msg-up):
* lisp/mouse-drag.el (mouse-drag-should-do-col-scrolling):
* mpc.el (mpc-tagbrowser, mpc):
* net/rcirc.el (rcirc-any-buffer):
* play/gomoku.el (gomoku-max-width, gomoku-max-height):
* play/landmark.el (landmark-max-width, landmark-max-height):
* play/zone.el (zone):
* progmodes/compile.el (compilation-goto-locus):
* progmodes/ebrowse.el (ebrowse-view/find-file-and-search-pattern):
* progmodes/etags.el (find-tag-other-window):
* progmodes/fortran.el (fortran-column-ruler):
* progmodes/gdb-mi.el (gdb-mouse-toggle-breakpoint-fringe):
* progmodes/verilog-mode.el (verilog-point-text):
* reposition.el (reposition-window):
* rot13.el (toggle-rot13-mode):
* server.el (server-switch-buffer):
* shell.el (shell-dynamic-complete-command)
(shell-dynamic-complete-environment-variable):
* simple.el (insert-buffer, set-selective-display)
(delete-completion-window):
* speedbar.el (speedbar-timer-fn, speedbar-center-buffer-smartly)
(speedbar-recenter):
* startup.el (fancy-splash-head):
* textmodes/ispell.el (ispell-command-loop):
* textmodes/makeinfo.el (makeinfo-compilation-sentinel-region):
* tutorial.el (help-with-tutorial):
* vc/add-log.el (add-change-log-entry):
* vc/compare-w.el (compare-windows):
* vc/ediff-help.el (ediff-indent-help-message):
* vc/ediff-util.el (ediff-setup-control-buffer, ediff-position-region):
* vc/ediff-wind.el (ediff-skip-unsuitable-frames)
(ediff-setup-control-frame):
* vc/emerge.el (emerge-position-region):
* vc/pcvs-util.el (cvs-bury-buffer):
* window.el (walk-windows, mouse-autoselect-window-select):
* winner.el (winner-set-conf, winner-undo): Related users changed.
2013-08-05 18:26:57 +04:00
|
|
|
(prog2 (unless (window-minibuffer-p)
|
2008-03-21 23:52:27 +00:00
|
|
|
(message "Completing variable name..."))
|
2021-08-19 18:01:06 +02:00
|
|
|
(completion-in-region (nth 0 data) (nth 1 data) (nth 2 data))))))
|
2011-04-20 19:31:06 -03:00
|
|
|
|
|
|
|
|
|
|
|
(defun shell-environment-variable-completion ()
|
|
|
|
"Completion data for an environment variable at point, if any."
|
|
|
|
(let* ((var (shell-match-partial-variable))
|
|
|
|
(end (match-end 0)))
|
|
|
|
(when (and (not (zerop (length var))) (eq (aref var 0) ?$))
|
|
|
|
(let* ((start
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
(looking-at "\\$?[({]*")
|
|
|
|
(match-end 0)))
|
|
|
|
(variables (mapcar (lambda (x)
|
Use string-search instead of string-match[-p]
`string-search` is easier to understand, less error-prone, much
faster, does not pollute the regexp cache, and does not mutate global
state. Use it where applicable and obviously safe (erring on the
conservative side).
* admin/authors.el (authors-canonical-file-name)
(authors-scan-change-log):
* lisp/apropos.el (apropos-command)
(apropos-documentation-property, apropos-symbols-internal):
* lisp/arc-mode.el (archive-arc-summarize)
(archive-zoo-summarize):
* lisp/calc/calc-aent.el (math-read-factor):
* lisp/calc/calc-ext.el (math-read-big-expr)
(math-format-nice-expr, math-format-number-fancy):
* lisp/calc/calc-forms.el (math-read-angle-brackets):
* lisp/calc/calc-graph.el (calc-graph-set-range):
* lisp/calc/calc-keypd.el (calc-keypad-press):
* lisp/calc/calc-lang.el (tex, latex, math-read-big-rec):
* lisp/calc/calc-prog.el (calc-fix-token-name)
(calc-user-define-permanent, math-define-exp):
* lisp/calc/calc.el (calc-record, calcDigit-key)
(calc-count-lines):
* lisp/calc/calcalg2.el (calc-solve-for, calc-poly-roots)
(math-do-integral):
* lisp/calc/calcalg3.el (calc-find-root, calc-find-minimum)
(calc-get-fit-variables):
* lisp/cedet/ede/speedbar.el (ede-tag-expand):
* lisp/cedet/semantic/java.el (semantic-java-expand-tag):
* lisp/cedet/semantic/sb.el (semantic-sb-show-extra)
(semantic-sb-expand-group):
* lisp/cedet/semantic/wisent/python.el
(semantic-python-instance-variable-p):
* lisp/cus-edit.el (get):
* lisp/descr-text.el (describe-text-sexp):
* lisp/dired-aux.el (dired-compress-file):
* lisp/dired-x.el (dired-make-relative-symlink):
* lisp/dired.el (dired-glob-regexp):
* lisp/dos-fns.el (dos-convert-standard-filename, dos-8+3-filename):
* lisp/edmacro.el (edmacro-format-keys):
* lisp/emacs-lisp/eieio-opt.el (eieio-sb-expand):
* lisp/emacs-lisp/eieio-speedbar.el (eieio-speedbar-object-expand):
* lisp/emacs-lisp/lisp-mnt.el (lm-keywords-list):
* lisp/emacs-lisp/warnings.el (display-warning):
* lisp/emulation/viper-ex.el (viper-ex-read-file-name)
(ex-print-display-lines):
* lisp/env.el (read-envvar-name, setenv):
* lisp/epa-mail.el (epa-mail-encrypt):
* lisp/epg.el (epg--start):
* lisp/erc/erc-backend.el (erc-parse-server-response):
* lisp/erc/erc-dcc.el (erc-dcc-member):
* lisp/erc/erc-speedbar.el (erc-speedbar-expand-server)
(erc-speedbar-expand-channel, erc-speedbar-expand-user):
* lisp/erc/erc.el (erc-send-input):
* lisp/eshell/em-glob.el (eshell-glob-entries):
* lisp/eshell/esh-proc.el (eshell-needs-pipe-p):
* lisp/eshell/esh-util.el (eshell-convert):
* lisp/eshell/esh-var.el (eshell-envvar-names):
* lisp/faces.el (x-resolve-font-name):
* lisp/ffap.el (ffap-file-at-point):
* lisp/files.el (wildcard-to-regexp, shell-quote-wildcard-pattern):
* lisp/forms.el (forms--update):
* lisp/frameset.el (frameset-filter-unshelve-param):
* lisp/gnus/gnus-art.el (article-decode-charset):
* lisp/gnus/gnus-kill.el (gnus-kill-parse-rn-kill-file):
* lisp/gnus/gnus-mlspl.el (gnus-group-split-fancy):
* lisp/gnus/gnus-msg.el (gnus-summary-resend-message-insert-gcc)
(gnus-inews-insert-gcc):
* lisp/gnus/gnus-rfc1843.el (rfc1843-decode-article-body):
* lisp/gnus/gnus-search.el (gnus-search-indexed-parse-output)
(gnus-search--complete-key-data):
* lisp/gnus/gnus-spec.el (gnus-parse-simple-format):
* lisp/gnus/gnus-sum.el (gnus-summary-refer-article):
* lisp/gnus/gnus-util.el (gnus-extract-address-components)
(gnus-newsgroup-directory-form):
* lisp/gnus/gnus-uu.el (gnus-uu-grab-view):
* lisp/gnus/gnus.el (gnus-group-native-p, gnus-short-group-name):
* lisp/gnus/message.el (message-check-news-header-syntax)
(message-make-message-id, message-user-mail-address)
(message-make-fqdn, message-get-reply-headers, message-followup):
* lisp/gnus/mm-decode.el (mm-dissect-buffer):
* lisp/gnus/nnheader.el (nnheader-insert):
* lisp/gnus/nnimap.el (nnimap-process-quirk)
(nnimap-imap-ranges-to-gnus-ranges):
* lisp/gnus/nnmaildir.el (nnmaildir--ensure-suffix):
* lisp/gnus/nnmairix.el (nnmairix-determine-original-group-from-path):
* lisp/gnus/nnrss.el (nnrss-match-macro):
* lisp/gnus/nntp.el (nntp-find-group-and-number):
* lisp/help-fns.el (help--symbol-completion-table-affixation):
* lisp/help.el (help-function-arglist):
* lisp/hippie-exp.el (he-concat-directory-file-name):
* lisp/htmlfontify.el (hfy-relstub):
* lisp/ido.el (ido-make-prompt, ido-complete, ido-copy-current-word)
(ido-exhibit):
* lisp/image/image-converter.el (image-convert-p):
* lisp/info-xref.el (info-xref-docstrings):
* lisp/info.el (Info-toc-build, Info-follow-reference)
(Info-backward-node, Info-finder-find-node)
(Info-speedbar-expand-node):
* lisp/international/mule-diag.el (print-fontset-element):
* lisp/language/korea-util.el (default-korean-keyboard):
* lisp/linum.el (linum-after-change):
* lisp/mail/ietf-drums.el (ietf-drums-parse-address):
* lisp/mail/mail-utils.el (mail-dont-reply-to):
* lisp/mail/rfc2047.el (rfc2047-encode-1, rfc2047-decode-string):
* lisp/mail/rfc2231.el (rfc2231-parse-string):
* lisp/mail/rmailkwd.el (rmail-set-label):
* lisp/mail/rmailsum.el (rmail-header-summary):
* lisp/mail/smtpmail.el (smtpmail-maybe-append-domain)
(smtpmail-user-mail-address):
* lisp/mail/uce.el (uce-reply-to-uce):
* lisp/man.el (Man-default-man-entry):
* lisp/mh-e/mh-alias.el (mh-alias-gecos-name)
(mh-alias-minibuffer-confirm-address):
* lisp/mh-e/mh-comp.el (mh-forwarded-letter-subject):
* lisp/mh-e/mh-speed.el (mh-speed-parse-flists-output):
* lisp/mh-e/mh-utils.el (mh-collect-folder-names-filter)
(mh-folder-completion-function):
* lisp/minibuffer.el (completion--make-envvar-table)
(completion-file-name-table, completion-flex-try-completion)
(completion-flex-all-completions):
* lisp/mpc.el (mpc--proc-quote-string, mpc-cmd-special-tag-p)
(mpc-constraints-tag-lookup):
* lisp/net/ange-ftp.el (ange-ftp-send-cmd)
(ange-ftp-allow-child-lookup):
* lisp/net/mailcap.el (mailcap-mime-types):
* lisp/net/mairix.el (mairix-search-thread-this-article):
* lisp/net/pop3.el (pop3-open-server):
* lisp/net/soap-client.el (soap-decode-xs-complex-type):
* lisp/net/socks.el (socks-filter):
* lisp/nxml/nxml-outln.el (nxml-highlighted-qname):
* lisp/nxml/rng-cmpct.el (rng-c-expand-name, rng-c-expand-datatype):
* lisp/nxml/rng-uri.el (rng-uri-file-name-1):
* lisp/obsolete/complete.el (partial-completion-mode)
(PC-do-completion):
* lisp/obsolete/longlines.el (longlines-encode-string):
* lisp/obsolete/nnir.el (nnir-compose-result):
* lisp/obsolete/terminal.el (te-quote-arg-for-sh):
* lisp/obsolete/tpu-edt.el (tpu-check-search-case):
* lisp/obsolete/url-ns.el (isPlainHostName):
* lisp/pcmpl-unix.el (pcomplete/scp):
* lisp/play/dunnet.el (dun-listify-string2, dun-get-path)
(dun-unix-parse, dun-doassign, dun-cat, dun-batch-unix-interface):
* lisp/progmodes/ebnf2ps.el: (ebnf-eps-header-footer-comment):
* lisp/progmodes/gdb-mi.el (gdb-var-delete)
(gdb-speedbar-expand-node, gdbmi-bnf-incomplete-record-result):
* lisp/progmodes/gud.el (gud-find-expr):
* lisp/progmodes/idlw-help.el (idlwave-do-context-help1):
* lisp/progmodes/idlw-shell.el (idlwave-shell-mode)
(idlwave-shell-filter-hidden-output, idlwave-shell-filter):
* lisp/progmodes/idlwave.el (idlwave-skip-label-or-case)
(idlwave-routine-info):
* lisp/progmodes/octave.el (inferior-octave-completion-at-point):
* lisp/progmodes/sh-script.el (sh-add-completer):
* lisp/progmodes/sql.el (defun):
* lisp/progmodes/xscheme.el (xscheme-process-filter):
* lisp/replace.el (query-replace-compile-replacement)
(map-query-replace-regexp):
* lisp/shell.el (shell--command-completion-data)
(shell-environment-variable-completion):
* lisp/simple.el (display-message-or-buffer):
* lisp/speedbar.el (speedbar-dired, speedbar-tag-file)
(speedbar-tag-expand):
* lisp/subr.el (split-string-and-unquote):
* lisp/tar-mode.el (tar-extract):
* lisp/term.el (term-command-hook, serial-read-name):
* lisp/textmodes/bibtex.el (bibtex-print-help-message):
* lisp/textmodes/ispell.el (ispell-lookup-words, ispell-filter)
(ispell-parse-output, ispell-buffer-local-parsing):
* lisp/textmodes/reftex-cite.el (reftex-do-citation):
* lisp/textmodes/reftex-parse.el (reftex-notice-new):
* lisp/textmodes/reftex-ref.el (reftex-show-entry):
* lisp/textmodes/reftex.el (reftex-compile-variables):
* lisp/textmodes/tex-mode.el (tex-send-command)
(tex-start-tex, tex-append):
* lisp/thingatpt.el (thing-at-point-url-at-point):
* lisp/tmm.el (tmm-add-one-shortcut):
* lisp/transient.el (transient-format-key):
* lisp/url/url-auth.el (url-basic-auth)
(url-digest-auth-directory-id-assoc):
* lisp/url/url-news.el (url-news):
* lisp/url/url-util.el (url-parse-query-string):
* lisp/vc/vc-cvs.el (vc-cvs-parse-entry):
* lisp/wid-browse.el (widget-browse-sexp):
* lisp/woman.el (woman-parse-colon-path, woman-mini-help)
(WoMan-getpage-in-background, woman-negative-vertical-space):
* lisp/xml.el:
* test/lisp/emacs-lisp/check-declare-tests.el
(check-declare-tests-warn):
* test/lisp/files-tests.el
(files-tests-file-name-non-special-dired-compress-handler):
* test/lisp/net/network-stream-tests.el (server-process-filter):
* test/src/coding-tests.el (ert-test-unibyte-buffer-dos-eol-decode):
Use `string-search` instead of `string-match` and `string-match-p`.
2021-08-09 11:20:00 +02:00
|
|
|
(substring x 0 (string-search "=" x)))
|
2011-04-20 19:31:06 -03:00
|
|
|
process-environment))
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
(suffix (pcase (char-before start) (?\{ "}") (?\( ")") (_ ""))))
|
2011-05-23 23:45:50 -03:00
|
|
|
(list start end variables
|
|
|
|
:exit-function
|
|
|
|
(lambda (s finished)
|
|
|
|
(when (memq finished '(sole finished))
|
|
|
|
(let ((suf (concat suffix
|
|
|
|
(if (file-directory-p
|
|
|
|
(comint-directory (getenv s)))
|
|
|
|
"/"))))
|
|
|
|
(if (looking-at (regexp-quote suf))
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
(insert suf))))))))))
|
2011-04-20 19:31:06 -03:00
|
|
|
|
|
|
|
|
|
|
|
(defun shell-c-a-p-replace-by-expanded-directory ()
|
|
|
|
"Expand directory stack reference before point.
|
|
|
|
For use on `completion-at-point-functions'."
|
|
|
|
(when (comint-match-partial-filename)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (match-beginning 0))
|
|
|
|
(let ((stack (cons default-directory shell-dirstack))
|
|
|
|
(index (cond ((looking-at "=-/?")
|
|
|
|
(length shell-dirstack))
|
|
|
|
((looking-at "=\\([0-9]+\\)/?")
|
|
|
|
(string-to-number
|
|
|
|
(buffer-substring
|
|
|
|
(match-beginning 1) (match-end 1)))))))
|
|
|
|
(when index
|
|
|
|
(let ((start (match-beginning 0))
|
|
|
|
(end (match-end 0))
|
|
|
|
(replacement (file-name-as-directory (nth index stack))))
|
|
|
|
(lambda ()
|
|
|
|
(cond
|
|
|
|
((>= index (length stack))
|
|
|
|
(error "Directory stack not that deep"))
|
|
|
|
(t
|
|
|
|
(save-excursion
|
|
|
|
(goto-char start)
|
|
|
|
(insert replacement)
|
|
|
|
(delete-char (- end start)))
|
|
|
|
(message "Directory item: %d" index)
|
|
|
|
t)))))))))
|
1994-03-03 23:37:27 +00:00
|
|
|
|
|
|
|
(defun shell-replace-by-expanded-directory ()
|
|
|
|
"Expand directory stack reference before point.
|
|
|
|
Directory stack references are of the form \"=digit\" or \"=-\".
|
|
|
|
See `default-directory' and `shell-dirstack'.
|
|
|
|
|
|
|
|
Returns t if successful."
|
|
|
|
(interactive)
|
2011-04-20 19:31:06 -03:00
|
|
|
(let ((f (shell-c-a-p-replace-by-expanded-directory)))
|
|
|
|
(if f (funcall f))))
|
2001-01-28 03:43:35 +00:00
|
|
|
|
2020-10-17 13:16:24 +02:00
|
|
|
(defun shell--prompt-begin-position ()
|
|
|
|
;; We need this convoluted function because `looking-at-p' does not work on
|
|
|
|
;; multiline regexps _and_ `re-search-backward' skips the current line.
|
|
|
|
(save-excursion
|
|
|
|
(let ((old-point (point)))
|
|
|
|
(max
|
|
|
|
(save-excursion
|
|
|
|
;; Right result if not on prompt.
|
|
|
|
(call-interactively #'comint-previous-prompt)
|
|
|
|
(re-search-backward comint-prompt-regexp)
|
|
|
|
(point))
|
|
|
|
(save-excursion
|
|
|
|
;; Right result if on first char after prompt.
|
|
|
|
(re-search-backward comint-prompt-regexp)
|
|
|
|
(point))
|
|
|
|
(save-excursion
|
|
|
|
;; Right result if on prompt.
|
|
|
|
(call-interactively #'comint-next-prompt)
|
|
|
|
(re-search-backward comint-prompt-regexp)
|
|
|
|
(if (<= (point) old-point)
|
|
|
|
(point)
|
|
|
|
(point-min)))))))
|
|
|
|
|
|
|
|
(defun shell--prompt-end-position ()
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (shell--prompt-begin-position))
|
|
|
|
(comint-next-prompt 1)
|
|
|
|
(point)))
|
|
|
|
|
|
|
|
(defun shell-narrow-to-prompt ()
|
|
|
|
"Narrow buffer to the command line (and any following command output) at point."
|
|
|
|
(interactive)
|
|
|
|
(let ((begin (shell--prompt-begin-position)))
|
|
|
|
(narrow-to-region
|
|
|
|
begin
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (shell--prompt-end-position))
|
|
|
|
(call-interactively #'comint-next-prompt)
|
|
|
|
(if (= begin (shell--prompt-begin-position))
|
|
|
|
(point-max)
|
|
|
|
(shell--prompt-begin-position))))))
|
|
|
|
|
2022-03-17 14:50:05 +01:00
|
|
|
(defun shell-eval-command (command)
|
|
|
|
"Eval COMMAND in the current shell process and return the result."
|
|
|
|
(let* ((proc (get-buffer-process (current-buffer)))
|
|
|
|
(old-filter (process-filter proc))
|
|
|
|
(result "")
|
|
|
|
prev)
|
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
(set-process-filter
|
|
|
|
proc
|
|
|
|
(lambda (_proc string)
|
|
|
|
(setq result (concat result string))))
|
|
|
|
(process-send-string proc command)
|
|
|
|
;; Wait until we get a prompt (which will be a line without
|
|
|
|
;; a newline). This is far from fool-proof -- if something
|
|
|
|
;; outputs incomplete data and then sleeps, we'll think
|
|
|
|
;; we've received the prompt.
|
2024-07-12 09:58:53 +03:00
|
|
|
(while (not (let* ((lines (string-lines result nil t))
|
|
|
|
(last (car (last lines)))
|
|
|
|
(last-end (if (equal last "")
|
|
|
|
last
|
|
|
|
(substring last -1))))
|
2022-03-17 14:50:05 +01:00
|
|
|
(and (length> lines 0)
|
2024-07-12 09:58:53 +03:00
|
|
|
(not (member last '("" "\n")))
|
|
|
|
(not (equal last-end "\n"))
|
2022-03-17 14:50:05 +01:00
|
|
|
(or (not prev)
|
|
|
|
(not (equal last prev)))
|
|
|
|
(setq prev last))))
|
|
|
|
(accept-process-output proc 0 100)))
|
|
|
|
;; Restore old filter.
|
|
|
|
(set-process-filter proc old-filter))
|
|
|
|
;; Remove the prompt.
|
|
|
|
(replace-regexp-in-string "\n.*\\'" "\n" result)))
|
|
|
|
|
2022-09-09 20:12:26 +02:00
|
|
|
;;; Highlight undefined commands
|
|
|
|
;;
|
|
|
|
;; To highlight non-existent shell commands, customize
|
|
|
|
;; `shell-highlight-undef-enable' to t. To highlight some shell
|
|
|
|
;; commands as aliases, add them to `shell-highlight-undef-aliases'.
|
|
|
|
|
|
|
|
(defcustom shell-highlight-undef-aliases nil
|
|
|
|
"List of shell commands to highlight as a command alias."
|
|
|
|
:group 'shell
|
|
|
|
:type '(repeat string)
|
|
|
|
:version "29.1")
|
|
|
|
|
|
|
|
(defface shell-highlight-undef-defined-face
|
2024-10-03 13:15:58 +02:00
|
|
|
'((t :inherit font-lock-function-name-face))
|
2022-09-09 22:10:00 +03:00
|
|
|
"Face used for existing shell commands."
|
2022-09-09 20:12:26 +02:00
|
|
|
:group 'shell
|
|
|
|
:version "29.1")
|
|
|
|
|
|
|
|
(defface shell-highlight-undef-undefined-face
|
2024-10-03 13:15:58 +02:00
|
|
|
'((t :inherit font-lock-warning-face))
|
2022-09-09 20:12:26 +02:00
|
|
|
"Face used for non-existent shell commands."
|
|
|
|
:group 'shell
|
|
|
|
:version "29.1")
|
|
|
|
|
|
|
|
(defface shell-highlight-undef-alias-face
|
2024-10-03 13:15:58 +02:00
|
|
|
'((t :inherit font-lock-variable-name-face))
|
2022-09-09 20:12:26 +02:00
|
|
|
"Face used for shell command aliases."
|
|
|
|
:group 'shell
|
|
|
|
:version "29.1")
|
|
|
|
|
|
|
|
(defcustom shell-highlight-undef-remote-file-name-inhibit-cache nil
|
2022-09-09 22:10:00 +03:00
|
|
|
"Whether to inhibit cache for fontifying shell commands in remote buffers.
|
|
|
|
When fontification of non-existent commands is enabled in a
|
|
|
|
remote shell buffer, use a cache to speed up searching for
|
2023-09-22 11:27:29 +02:00
|
|
|
executable files on the remote machine. This option controls
|
|
|
|
expiry of the cache. See `remote-file-name-inhibit-cache' for
|
|
|
|
a description of the possible options."
|
2022-09-09 20:12:26 +02:00
|
|
|
:group 'faces
|
|
|
|
:type '(choice
|
2023-09-22 11:27:29 +02:00
|
|
|
(const :tag "Do not cache remote executables" t)
|
|
|
|
(const :tag "Cache remote executables" nil)
|
|
|
|
(integer :tag "Cache remote executables with expiration"
|
|
|
|
:format "Cache expiry in seconds: %v"
|
2022-09-09 20:12:26 +02:00
|
|
|
:value 10))
|
|
|
|
:version "29.1")
|
|
|
|
|
|
|
|
(defvar shell--highlight-undef-exec-cache nil
|
|
|
|
"Cache of executable files found in `exec-path'.
|
|
|
|
An alist, whose elements are of the form
|
|
|
|
\(REMOTE TIME EXECUTABLES), where REMOTE is a string, returned by
|
2022-09-09 22:10:00 +03:00
|
|
|
`file-remote-p', TIME is the return value of `float-time', and
|
2022-09-09 20:12:26 +02:00
|
|
|
EXECUTABLES is a hash table with keys being the base-names of
|
|
|
|
executable files.
|
|
|
|
|
|
|
|
Cache expiry is controlled by the user option
|
2023-09-22 11:27:29 +02:00
|
|
|
`shell-highlight-undef-remote-file-name-inhibit-cache'.")
|
2022-09-09 20:12:26 +02:00
|
|
|
|
|
|
|
(defvar shell--highlight-undef-face 'shell-highlight-undef-defined-face)
|
|
|
|
|
|
|
|
(defvar shell-highlight-undef-keywords
|
|
|
|
`((,#'shell-highlight-undef-matcher 6 shell--highlight-undef-face)))
|
|
|
|
|
|
|
|
(defvar-local shell-highlight-undef-regexp regexp-unmatchable)
|
|
|
|
|
|
|
|
(defun shell--highlight-undef-executable-find (command)
|
|
|
|
"Return non-nil if COMMAND is found in `exec-path'.
|
|
|
|
Similar to `executable-find', but use cache stored in
|
|
|
|
`shell--highlight-undef-exec-cache'."
|
|
|
|
(let ((remote (file-remote-p default-directory))
|
|
|
|
as ret found-in-cache delta-time)
|
|
|
|
(if (null remote)
|
|
|
|
(executable-find command)
|
|
|
|
|
|
|
|
(setq delta-time
|
|
|
|
shell-highlight-undef-remote-file-name-inhibit-cache)
|
|
|
|
|
|
|
|
(pcase (setq as (assoc remote shell--highlight-undef-exec-cache))
|
|
|
|
(`(,_ ,time ,hash)
|
|
|
|
(when (pcase delta-time
|
|
|
|
((pred numberp) (<= (float-time) (+ time delta-time)))
|
|
|
|
('t nil)
|
|
|
|
('nil t))
|
|
|
|
(setq ret (gethash command hash))
|
|
|
|
(setq found-in-cache t)))
|
|
|
|
(_ (setq as (list remote 0 (make-hash-table :test #'equal)))
|
|
|
|
(push as shell--highlight-undef-exec-cache)))
|
|
|
|
|
|
|
|
(if found-in-cache
|
|
|
|
ret
|
|
|
|
;; Build cache
|
|
|
|
(setcar (cdr as) (float-time))
|
|
|
|
(let ((hash (clrhash (caddr as))))
|
|
|
|
(dolist (dir (exec-path))
|
|
|
|
(pcase-dolist (`(,f . ,attr)
|
|
|
|
(condition-case nil
|
|
|
|
(directory-files-and-attributes
|
|
|
|
(concat remote dir) nil nil 'nosort 'integer)
|
|
|
|
(file-error nil)))
|
|
|
|
;; Approximation. Assume every non-directory file in $PATH is an
|
|
|
|
;; executable. Alternatively, we could check
|
|
|
|
;; `file-executable-p', but doing so for every file in $PATH is
|
|
|
|
;; slow on remote machines.
|
|
|
|
(unless (eq t (file-attribute-type attr))
|
|
|
|
(puthash f t hash))))
|
|
|
|
(gethash command hash))))))
|
|
|
|
|
|
|
|
(defun shell-highlight-undef-matcher (end)
|
|
|
|
"Matcher used to highlight shell commands up to END."
|
|
|
|
(when (re-search-forward shell-highlight-undef-regexp end t)
|
|
|
|
(save-match-data
|
|
|
|
(let ((cmd (match-string 6))
|
|
|
|
(beg (match-beginning 6)))
|
|
|
|
(setq shell--highlight-undef-face
|
|
|
|
(let* ((buf (buffer-base-buffer))
|
|
|
|
(default-directory
|
|
|
|
(if buf (buffer-local-value 'default-directory buf)
|
|
|
|
default-directory)))
|
|
|
|
(cond
|
2022-09-30 20:28:15 +02:00
|
|
|
;; Don't fontify command output. Mostly useful if
|
|
|
|
;; `comint-fontify-input-mode' is disabled.
|
2022-09-09 20:12:26 +02:00
|
|
|
((text-property-any beg (point) 'field 'output)
|
|
|
|
nil)
|
|
|
|
((member cmd shell-highlight-undef-aliases)
|
|
|
|
'shell-highlight-undef-alias-face)
|
|
|
|
;; Check if it contains a directory separator
|
|
|
|
((file-name-directory cmd)
|
|
|
|
(when (file-name-absolute-p cmd)
|
|
|
|
(setq cmd (concat
|
|
|
|
(or (bound-and-true-p comint-file-name-prefix)
|
|
|
|
(file-remote-p default-directory))
|
|
|
|
cmd)))
|
|
|
|
(if (or (file-executable-p cmd)
|
|
|
|
(file-directory-p cmd))
|
|
|
|
'shell-highlight-undef-defined-face
|
|
|
|
'shell-highlight-undef-undefined-face))
|
|
|
|
((shell--highlight-undef-executable-find cmd)
|
|
|
|
'shell-highlight-undef-defined-face)
|
|
|
|
(t 'shell-highlight-undef-undefined-face))))))
|
|
|
|
t))
|
|
|
|
|
|
|
|
(defvar-local shell--highlight-undef-indirect nil
|
2022-09-11 12:59:02 +02:00
|
|
|
"Non-nil if shell commands are fontified in `comint-indirect-buffer'.")
|
2022-09-09 20:12:26 +02:00
|
|
|
|
|
|
|
(declare-function sh-feature "sh-script" (alist &optional function))
|
|
|
|
(defvar sh-leading-keywords)
|
|
|
|
(defvar sh-other-keywords)
|
|
|
|
|
|
|
|
(define-minor-mode shell-highlight-undef-mode
|
|
|
|
"Highlight undefined shell commands and aliases.
|
|
|
|
This minor mode is mostly useful in `shell-mode' buffers and
|
2022-09-30 20:28:15 +02:00
|
|
|
works better if `comint-fontify-input-mode' is enabled."
|
2022-09-09 20:12:26 +02:00
|
|
|
:init-value nil
|
|
|
|
(if shell--highlight-undef-indirect
|
|
|
|
(progn
|
|
|
|
(remove-hook 'comint-indirect-setup-hook shell--highlight-undef-indirect t)
|
|
|
|
(setq shell--highlight-undef-indirect nil)
|
Mark if-let and when-let obsolete
* lisp/subr.el (if-let*, when-let*, if-let, when-let): Mark
if-let and when-let obsolete (bug#73853 and elsewhere). Move
docstring text around so that if-let* and when-let* descriptions
no longer refer to if-let and when-let.
* etc/NEWS: Announce the change.
* admin/admin.el (reminder-for-release-blocking-bugs):
* doc/misc/erc.texi (display-buffer):
* lisp/ansi-color.el (ansi-color-apply)
(ansi-color--face-vec-face):
* lisp/ansi-osc.el (ansi-osc-apply-on-region)
(ansi-osc-hyperlink):
* lisp/arc-mode.el (archive-goto-file)
(archive-next-file-displayer):
* lisp/auth-source-pass.el (auth-source-pass-search)
(auth-source-pass--parse-data)
(auth-source-pass--find-match-many):
* lisp/autorevert.el (auto-revert-notify-rm-watch):
* lisp/buff-menu.el (Buffer-menu-unmark-all-buffers)
(Buffer-menu-group-by-root):
* lisp/calendar/parse-time.el (parse-iso8601-time-string):
* lisp/cedet/pulse.el (pulse-tick):
* lisp/comint.el (comint--fontify-input-ppss-flush-indirect)
(comint--intersect-regions):
* lisp/completion-preview.el (completion-preview--try-table)
(completion-preview--capf-wrapper, completion-preview--update):
* lisp/cus-edit.el (setopt--set)
(custom-dirlocals-maybe-update-cons, custom-dirlocals-validate):
* lisp/custom.el (load-theme):
* lisp/descr-text.el (describe-char):
* lisp/desktop.el (desktop--emacs-pid-running-p):
* lisp/dired-x.el (menu):
* lisp/dired.el (dired-font-lock-keywords)
(dired-insert-directory, dired--insert-disk-space, dired-mode):
* lisp/dnd.el (dnd-handle-multiple-urls):
* lisp/dom.el (dom-remove-attribute):
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
* lisp/emacs-lisp/bytecomp.el (bytecomp--custom-declare):
* lisp/emacs-lisp/comp-common.el (comp-function-type-spec):
* lisp/emacs-lisp/comp-cstr.el (comp--all-classes)
(comp-cstr-set-range-for-arithm, comp--cstr-union-1-no-mem)
(comp-cstr-intersection-no-mem, comp-cstr-fixnum-p)
(comp-cstr-type-p):
* lisp/emacs-lisp/comp-run.el (comp-subr-trampoline-install)
(native--compile-async):
* lisp/emacs-lisp/comp.el (comp--get-function-cstr)
(comp--function-pure-p, comp--intern-func-in-ctxt)
(comp--addr-to-bb-name, comp--emit-assume, comp--maybe-add-vmvar)
(comp--add-call-cstr, comp--compute-dominator-tree)
(comp--dom-tree-walker, comp--ssa-rename)
(comp--function-call-maybe-fold, comp--fwprop-call)
(comp--call-optim-func):
* lisp/emacs-lisp/edebug.el (edebug-global-prefix)
(edebug-remove-instrumentation):
* lisp/emacs-lisp/eieio.el (initialize-instance):
* lisp/emacs-lisp/ert-x.el (ert-resource-directory):
* lisp/emacs-lisp/ert.el (ert--expand-should-1)
(ert-test-location, ert-write-junit-test-report)
(ert-test--erts-test):
* lisp/emacs-lisp/icons.el (icon-complete-spec, icon-string)
(icons--create):
* lisp/emacs-lisp/lisp-mode.el (lisp--local-defform-body-p):
* lisp/emacs-lisp/loaddefs-gen.el
(loaddefs-generate--make-autoload)
(loaddefs-generate--parse-file):
* lisp/emacs-lisp/multisession.el
(multisession-edit-mode--revert, multisession-edit-value):
* lisp/emacs-lisp/package-vc.el (package-vc--read-archive-data)
(package-vc--version, package-vc--clone):
* lisp/emacs-lisp/package.el (package--reload-previously-loaded):
* lisp/emacs-lisp/pp.el (pp--insert-lisp):
* lisp/emacs-lisp/subr-x.el (add-display-text-property):
* lisp/emacs-lisp/tabulated-list.el (tabulated-list-print):
* lisp/emacs-lisp/timer.el (run-at-time):
* lisp/emacs-lisp/vtable.el (vtable-goto-table)
(vtable-goto-column, vtable-update-object, vtable--insert-line)
(vtable--compute-widths, vtable--make-keymap):
* lisp/emacs-lisp/warnings.el (display-warning):
* lisp/epa-file.el (epa-file-insert-file-contents):
* lisp/epa.el (epa-show-key):
* lisp/erc/erc-backend.el (erc--split-line, erc--conceal-prompt)
(PRIVMSG, erc--get-isupport-entry):
* lisp/erc/erc-button.el (erc-button-add-nickname-buttons)
(erc--button-next):
* lisp/erc/erc-common.el (erc--find-group):
* lisp/erc/erc-fill.el (erc-fill, erc-fill-static)
(erc-fill--wrap-escape-hidden-speaker)
(erc-fill--wrap-unmerge-on-date-stamp)
(erc-fill--wrap-massage-initial-message-post-clear)
(erc-fill-wrap, erc-fill--wrap-rejigger-region):
* lisp/erc/erc-goodies.el (erc--scrolltobottom-all)
(erc--keep-place-indicator-on-window-buffer-change)
(keep-place-indicator, erc--keep-place-indicator-adjust-on-clear)
(erc-keep-place-move, erc--command-indicator-display):
* lisp/erc/erc-ibuffer.el (erc-members):
* lisp/erc/erc-join.el (erc-join--remove-requested-channel)
(erc-autojoin--join):
* lisp/erc/erc-networks.el
(erc-networks--id-qualifying-init-parts, erc-networks--id-reload)
(erc-networks--id-ensure-comparable)
(erc-networks--reclaim-orphaned-target-buffers)
(erc-networks--server-select):
* lisp/erc/erc-nicks.el (erc-nicks-invert)
(erc-nicks--redirect-face-widget-link, erc-nicks--highlight)
(erc-nicks--highlight-button)
(erc-nicks--list-faces-help-button-action, erc-nicks-list-faces)
(erc-nicks-refresh, erc-nicks--colors-from-faces)
(erc-nicks--track-prioritize)
(erc-nicks--remember-face-for-track):
* lisp/erc/erc-notify.el (querypoll, erc--querypoll-get-next)
(erc--querypoll-on-352, erc--querypoll-send):
* lisp/erc/erc-sasl.el (erc-sasl--read-password):
* lisp/erc/erc-services.el
(erc-services-issue-ghost-and-retry-nick):
* lisp/erc/erc-speedbar.el (erc-speedbar--ensure, nickbar)
(erc-speedbar-toggle-nicknames-window-lock)
(erc-speedbar--compose-nicks-face):
* lisp/erc/erc-stamp.el (erc-stamp--recover-on-reconnect)
(erc-stamp-prefix-log-filter, erc--conceal-prompt)
(erc--insert-timestamp-left, erc-insert-timestamp-right)
(erc-stamp--defer-date-insertion-on-post-modify)
(erc-insert-timestamp-left-and-right)
(erc-stamp--redo-right-stamp-post-clear)
(erc-stamp--reset-on-clear, erc-stamp--dedupe-date-stamps):
* lisp/erc/erc-status-sidebar.el (bufbar)
(erc-status-sidebar-prefer-target-as-name)
(erc-status-sidebar-default-allsort, erc-status-sidebar-click):
* lisp/erc/erc-track.el (erc-track--shortened-names-get)
(erc-track--setup, erc-track--select-mode-line-face)
(erc-track-modified-channels, erc-track--collect-faces-in)
(erc-track--switch-buffer, erc-track--replace-killed-buffer):
* lisp/erc/erc-truncate.el (erc-truncate--setup)
(erc-truncate-buffer):
* lisp/erc/erc.el (erc--ensure-query-member)
(erc--ensure-query-members, erc--remove-channel-users-but)
(erc--cusr-change-status, erc--find-mode, erc--update-modules)
(erc-log-irc-protocol, erc--refresh-prompt)
(erc--restore-important-text-props)
(erc--order-text-properties-from-hash, erc-send-input-line)
(erc-cmd-IGNORE, erc--unignore-user, erc-cmd-QUERY)
(erc-cmd-BANLIST, erc--speakerize-nick)
(erc--format-speaker-input-message, erc-channel-receive-names)
(erc-send-current-line, erc-format-target-and/or-network)
(erc-kill-buffer-function, erc-restore-text-properties)
(erc--get-eq-comparable-cmd):
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias--which)
(eshell-maybe-replace-by-alias):
* lisp/eshell/em-glob.el (eshell-glob-convert):
* lisp/eshell/em-pred.el (eshell-pred-user-or-group)
(eshell-pred-file-time, eshell-pred-file-type)
(eshell-pred-file-mode, eshell-pred-file-links)
(eshell-pred-file-size):
* lisp/eshell/em-prompt.el (eshell-forward-paragraph)
(eshell-next-prompt):
* lisp/eshell/esh-arg.el (eshell-resolve-current-argument):
* lisp/eshell/esh-cmd.el (eshell-do-eval, eshell/which)
(eshell-plain-command--which, eshell-plain-command):
* lisp/eshell/esh-io.el (eshell-duplicate-handles)
(eshell-protect-handles, eshell-get-target, eshell-close-target):
* lisp/eshell/esh-proc.el (eshell-sentinel):
* lisp/eshell/esh-var.el (eshell-parse-variable-ref)
(eshell-get-variable, eshell-set-variable):
* lisp/faces.el (face-at-point):
* lisp/ffap.el (ffap-in-project):
* lisp/filenotify.el (file-notify--rm-descriptor):
* lisp/files-x.el (read-dir-locals-file)
(connection-local-update-profile-variables)
(connection-local-value):
* lisp/files.el (file-remote-p, abbreviate-file-name)
(set-auto-mode, hack-local-variables)
(revert-buffer-restore-read-only):
* lisp/find-dired.el (find-dired-sort-by-filename):
* lisp/font-lock.el (font-lock--filter-keywords):
* lisp/gnus/gnus-art.el (article-emojize-symbols):
* lisp/gnus/gnus-int.el (gnus-close-server):
* lisp/gnus/gnus-search.el (gnus-search-transform)
(gnus-search-indexed-parse-output, gnus-search-server-to-engine):
* lisp/gnus/gnus-sum.el (gnus-collect-urls, gnus-shorten-url):
* lisp/gnus/gnus.el (gnus-check-backend-function):
* lisp/gnus/message.el (message-send-mail):
* lisp/gnus/mml.el (mml-generate-mime, mml-insert-mime-headers):
* lisp/gnus/nnatom.el (nnatom--read-feed, nnatom--read-article)
(nnatom--read-article-or-group-authors, nnatom--read-publish)
(nnatom--read-update, nnatom--read-links):
* lisp/gnus/nnfeed.el (nnfeed--read-server, nnfeed--write-server)
(nnfeed--parse-feed, nnfeed--group-data, nnfeed-retrieve-article)
(nnfeed-retrieve-headers, nnfeed--print-part)
(nnfeed-request-article, nnfeed-request-group)
(nnfeed-request-list, nnfeed--group-description)
(nnfeed-request-group-description)
(nnfeed-request-list-newsgroups, nnfeed-request-rename-group):
* lisp/gnus/nnmh.el (nnmh-update-gnus-unreads):
* lisp/help-fns.el (help-find-source)
(help-fns--insert-menu-bindings, help-fns--mention-first-release)
(help-fns--mention-shortdoc-groups)
(help-fns--customize-variable-version)
(help-fns--face-custom-version-info, describe-mode):
* lisp/help-mode.el (help-make-xrefs):
* lisp/help.el (help-key-description, help--describe-command):
* lisp/hfy-cmap.el (htmlfontify-load-rgb-file):
* lisp/ibuf-ext.el (ibuffer-jump-to-filter-group)
(ibuffer-kill-filter-group, ibuffer-kill-line)
(ibuffer-save-filter-groups, ibuffer-save-filters, filename)
(basename, file-extension, ibuffer-diff-buffer-with-file-1)
(ibuffer-mark-by-file-name-regexp)
(ibuffer-mark-by-content-regexp):
* lisp/ibuf-macs.el (ibuffer-aif, ibuffer-awhen):
* lisp/ibuffer.el (ibuffer-mouse-toggle-mark)
(ibuffer-toggle-marks, ibuffer-mark-interactive)
(ibuffer-compile-format, process, ibuffer-map-lines):
* lisp/image.el (image--compute-map)
(image--compute-original-map):
* lisp/image/exif.el (exif-parse-buffer):
* lisp/image/image-converter.el (image-convert-p, image-convert)
(image-converter--find-converter):
* lisp/image/image-dired-util.el
(image-dired-file-name-at-point):
* lisp/image/image-dired.el (image-dired-track-original-file)
(image-dired--on-file-in-dired-buffer)
(image-dired--with-thumbnail-buffer)
(image-dired-jump-original-dired-buffer)
(image-dired--slideshow-step, image-dired-display-image):
* lisp/image/wallpaper.el (wallpaper--init-action-kill)
(wallpaper--find-setter, wallpaper--find-command)
(wallpaper--find-command-args, wallpaper--x-monitor-name):
* lisp/info-look.el (info-lookup-interactive-arguments)
(info-complete)::(:mode):
* lisp/info.el (info-pop-to-buffer, Info-read-node-name-1):
* lisp/international/emoji.el (emoji--adjust-displayable-1)
(emoji--add-recent):
* lisp/jsonrpc.el (jsonrpc--call-deferred)
(jsonrpc--process-sentinel, jsonrpc--remove):
* lisp/keymap.el (keymap-local-lookup):
* lisp/mail/emacsbug.el (report-emacs-bug-hook)
(submit-emacs-patch):
* lisp/mail/ietf-drums.el (ietf-drums-parse-addresses):
* lisp/mail/mailclient.el (mailclient-send-it):
* lisp/mail/rfc6068.el (rfc6068-parse-mailto-url):
* lisp/mail/undigest.el (rmail-digest-parse-mixed-mime):
* lisp/minibuffer.el (completion-metadata-get)
(completions--after-change)
(minibuffer-visible-completions--filter):
* lisp/net/browse-url.el (browse-url-url-at-point)
(browse-url-file-url, browse-url-emacs):
* lisp/net/dbus.el (dbus-byte-array-to-string)
(dbus-monitor-goto-serial):
* lisp/net/dictionary.el (dictionary-search):
* lisp/net/eww.el (eww--download-directory)
(eww-auto-rename-buffer, eww-open-in-new-buffer, eww-submit)
(eww-follow-link, eww-read-alternate-url)
(eww-copy-alternate-url):
* lisp/net/goto-addr.el (goto-address-at-point):
* lisp/net/mailcap.el (mailcap-mime-info):
* lisp/net/rcirc.el (rcirc, rcirc-connect, rcirc-send-string)
(rcirc-kill-buffer-hook, rcirc-print, rcirc-when)
(rcirc-color-attributes, rcirc-handler-NICK)
(rcirc-handler-TAGMSG, rcirc-handler-BATCH):
* lisp/net/shr.el (shr-descend, shr-adaptive-fill-function)
(shr-correct-dom-case, shr-tag-a):
* lisp/net/sieve.el (sieve-manage-quit):
* lisp/outline.el (outline-cycle-buffer):
* lisp/pcmpl-git.el (pcmpl-git--tracked-file-predicate):
* lisp/proced.el (proced-auto-update-timer):
* lisp/progmodes/bug-reference.el
(bug-reference-try-setup-from-vc):
* lisp/progmodes/c-ts-common.el (c-ts-common--fill-paragraph):
* lisp/progmodes/c-ts-mode.el (c-ts-mode--preproc-offset)
(c-ts-mode--anchor-prev-sibling, c-ts-mode-indent-defun):
* lisp/progmodes/compile.el (compilation-error-properties)
(compilation-find-file-1):
* lisp/progmodes/eglot.el (eglot--check-object)
(eglot--read-server, eglot-upgrade-eglot)
(eglot-handle-notification, eglot--CompletionParams)
(eglot-completion-at-point, eglot--sig-info)
(eglot-register-capability):
* lisp/progmodes/elisp-mode.el
(emacs-lisp-native-compile-and-load)
(elisp-eldoc-var-docstring-with-value):
* lisp/progmodes/erts-mode.el (erts-mode--goto-start-of-test):
* lisp/progmodes/flymake.el (flymake--update-eol-overlays)
(flymake-eldoc-function):
* lisp/progmodes/gdb-mi.el (gdb-breakpoints-list-handler-custom)
(gdb-frame-handler):
* lisp/progmodes/go-ts-mode.el (go-ts-mode-docstring)
(go-ts-mode--comment-on-previous-line-p)
(go-ts-mode--get-test-regexp-at-point)
(go-ts-mode-test-this-file):
* lisp/progmodes/grep.el (lgrep, rgrep-default-command)
(grep-file-at-point):
* lisp/progmodes/perl-mode.el (perl--end-of-format-p):
* lisp/progmodes/php-ts-mode.el
(php-ts-mode--anchor-prev-sibling, php-ts-mode--indent-defun):
* lisp/progmodes/project.el (project--other-place-command)
(project--find-default-from, project--transplant-file-name)
(project-prefixed-buffer-name, project--remove-from-project-list)
(project-prompt-project-name, project-remember-projects-under)
(project--switch-project-command)
(project-uniquify-dirname-transform, project-mode-line-format):
* lisp/progmodes/python.el
(python-font-lock-keywords-maximum-decoration)
(python--treesit-fontify-union-types)
(python-shell-get-process-name, python-shell-restart)
(python-shell-completion-at-point, python-ffap-module-path)
(python-util-comint-end-of-output-p, python--import-sources)
(python-add-import, python-remove-import, python-fix-imports):
* lisp/progmodes/xref.el (xref--add-log-current-defun):
* lisp/repeat.el (repeat-echo-message-string):
* lisp/saveplace.el (save-place-dired-hook):
* lisp/server.el (server-save-buffers-kill-terminal):
* lisp/shadowfile.el (shadow-make-fullname)
(shadow-contract-file-name, shadow-define-literal-group):
* lisp/shell.el (shell-highlight-undef-mode):
* lisp/simple.el (command-completion-using-modes-p)
(command-execute, file-user-uid, file-group-gid)
(first-completion, last-completion, switch-to-completions):
* lisp/startup.el (startup--load-user-init-file):
* lisp/tab-line.el (tab-line-tabs-buffer-group-by-project):
* lisp/tar-mode.el (tar-goto-file, tar-next-file-displayer):
* lisp/term/android-win.el (android-encode-select-string)
(gui-backend-set-selection):
* lisp/term/haiku-win.el (haiku-dnd-convert-string)
(haiku-select-encode-xstring, haiku-select-encode-utf-8-string):
* lisp/textmodes/emacs-news-mode.el (emacs-news--buttonize):
* lisp/textmodes/ispell.el (ispell-completion-at-point):
* lisp/textmodes/sgml-mode.el (sgml-validate)
(html-mode--complete-at-point):
* lisp/textmodes/tex-mode.el (tex-recenter-output-buffer)
(xref-backend-references):
* lisp/thingatpt.el (thing-at-point-file-at-point)
(thing-at-point-face-at-point):
* lisp/thread.el (thread-list--get-status):
* lisp/time.el (world-clock-copy-time-as-kill, world-clock):
* lisp/touch-screen.el (touch-screen-handle-touch):
* lisp/treesit.el (treesit-language-at, treesit-node-at)
(treesit-node-on, treesit-buffer-root-node)
(treesit-node-field-name, treesit-local-parsers-at)
(treesit-local-parsers-on, treesit--cleanup-local-range-overlays)
(treesit-font-lock-recompute-features)
(treesit-font-lock-fontify-region, treesit-transpose-sexps)
(treesit-add-log-current-defun, treesit-major-mode-setup)
(treesit--explorer-refresh, treesit-install-language-grammar):
* lisp/url/url.el (url-retrieve-synchronously):
* lisp/vc/smerge-mode.el (smerge-diff):
* lisp/vc/vc-dir.el (vc-dir):
* lisp/vc/vc-dispatcher.el (vc-do-async-command):
* lisp/vc/vc-git.el (vc-git-dir--branch-headers)
(vc-git-dir--stash-headers, vc-git--log-edit-summary-check)
(vc-git-stash-list):
* lisp/vc/vc.el (vc-responsible-backend, vc-buffer-sync-fileset)
(vc-clone):
* lisp/visual-wrap.el (visual-wrap--apply-to-line):
* lisp/wid-edit.el (widget-text)
(widget-editable-list-insert-before):
* lisp/window-tool-bar.el
(window-tool-bar--keymap-entry-to-string):
* lisp/window.el (display-buffer, display-buffer-full-frame)
(window-point-context-set, window-point-context-use)
(window-point-context-use-default-function):
* lisp/xdg.el (xdg-current-desktop):
* lisp/xwidget.el (xwidget-webkit-callback):
* lisp/yank-media.el (yank-media--get-selection)
(yank-media-types):
* test/lisp/comint-tests.el
(comint-tests/test-password-function):
* test/lisp/completion-preview-tests.el
(completion-preview-tests--capf):
* test/lisp/cus-edit-tests.el (with-cus-edit-test):
* test/lisp/erc/erc-scenarios-base-local-modules.el
(-phony-sblm-):
* test/lisp/erc/erc-scenarios-stamp.el
(erc-scenarios-stamp--on-post-modify):
* test/lisp/erc/erc-services-tests.el
(erc-services-tests--asp-parse-entry):
* test/lisp/erc/erc-tests.el (erc-modules--internal-property)
(erc--find-mode, erc-tests--update-modules):
* test/lisp/erc/resources/erc-d/erc-d-i.el
(erc-d-i--parse-message):
* test/lisp/erc/resources/erc-d/erc-d-t.el
(erc-d-t-kill-related-buffers, erc-d-t-with-cleanup):
* test/lisp/erc/resources/erc-d/erc-d-tests.el
(erc-d-i--parse-message--irc-parser-tests):
* test/lisp/erc/resources/erc-d/erc-d-u.el
(erc-d-u--read-exchange-slowly):
* test/lisp/erc/resources/erc-d/erc-d.el (erc-d--expire)
(erc-d--finalize-done, erc-d--command-handle-all):
* test/lisp/erc/resources/erc-scenarios-common.el
(erc-scenarios-common-with-cleanup):
* test/lisp/erc/resources/erc-tests-common.el
(erc-tests--common-display-message)
(erc-tests-common-create-subprocess):
* test/lisp/ibuffer-tests.el (ibuffer-test-Bug25058):
* test/lisp/international/mule-tests.el
(mule-cmds-tests--ucs-names-missing-names):
* test/lisp/progmodes/python-tests.el
(python-tests-get-shell-interpreter)
(python-tests--get-interpreter-info):
* test/lisp/progmodes/ruby-ts-mode-tests.el
(ruby-ts-resource-file):
* test/lisp/replace-tests.el (replace-tests-with-undo):
* test/src/emacs-tests.el (emacs-tests--seccomp-debug):
* test/src/process-tests.el (process-tests--emacs-command)
(process-tests--emacs-binary, process-tests--dump-file):
* test/src/treesit-tests.el (treesit--ert-test-defun-navigation):
Replace use of the now-obsolete if-let and when-let.
2024-10-24 16:50:07 +08:00
|
|
|
(when-let* ((buf (comint-indirect-buffer t)))
|
2022-09-09 20:12:26 +02:00
|
|
|
(with-current-buffer buf
|
|
|
|
(font-lock-remove-keywords nil shell-highlight-undef-keywords))))
|
|
|
|
(font-lock-remove-keywords nil shell-highlight-undef-keywords))
|
2022-09-30 20:28:15 +02:00
|
|
|
(remove-hook 'comint-fontify-input-mode-hook
|
2022-09-11 12:59:02 +02:00
|
|
|
#'shell-highlight-undef-mode-restart t)
|
2022-09-09 20:12:26 +02:00
|
|
|
|
|
|
|
(when shell-highlight-undef-mode
|
|
|
|
(when comint-use-prompt-regexp
|
|
|
|
(setq shell-highlight-undef-mode nil)
|
|
|
|
(error
|
|
|
|
"`shell-highlight-undef-mode' is incompatible with `comint-use-prompt-regexp'"))
|
|
|
|
|
|
|
|
(require 'sh-script)
|
|
|
|
|
|
|
|
(let* ((regexp
|
|
|
|
;; Adapted from `sh-font-lock-keywords-1'
|
|
|
|
(concat
|
|
|
|
"\\("
|
|
|
|
"[;(){}`|&]"
|
2022-09-30 20:28:15 +02:00
|
|
|
(if comint-fontify-input-mode
|
|
|
|
;; `comint-fontify-input-mode' already puts
|
|
|
|
;; point-min on end of prompt
|
2022-09-09 20:12:26 +02:00
|
|
|
""
|
|
|
|
(concat "\\|" comint-prompt-regexp))
|
|
|
|
"\\|^"
|
|
|
|
"\\)"
|
|
|
|
"[ \t]*\\(\\("
|
|
|
|
(regexp-opt (sh-feature sh-leading-keywords) t)
|
|
|
|
"[ \t]+\\)?"
|
|
|
|
(regexp-opt (append (sh-feature sh-leading-keywords)
|
|
|
|
(sh-feature sh-other-keywords))
|
|
|
|
t)
|
|
|
|
"[ \t]+\\)?\\_<\\(\\(?:\\s_\\|\\sw\\|/\\)+\\)\\_>"))
|
|
|
|
(setup
|
|
|
|
(lambda ()
|
|
|
|
(setq shell-highlight-undef-regexp regexp)
|
|
|
|
(font-lock-add-keywords nil shell-highlight-undef-keywords t))))
|
2022-09-30 20:28:15 +02:00
|
|
|
(cond (comint-fontify-input-mode
|
2022-09-09 20:12:26 +02:00
|
|
|
(setq shell--highlight-undef-indirect setup)
|
Mark if-let and when-let obsolete
* lisp/subr.el (if-let*, when-let*, if-let, when-let): Mark
if-let and when-let obsolete (bug#73853 and elsewhere). Move
docstring text around so that if-let* and when-let* descriptions
no longer refer to if-let and when-let.
* etc/NEWS: Announce the change.
* admin/admin.el (reminder-for-release-blocking-bugs):
* doc/misc/erc.texi (display-buffer):
* lisp/ansi-color.el (ansi-color-apply)
(ansi-color--face-vec-face):
* lisp/ansi-osc.el (ansi-osc-apply-on-region)
(ansi-osc-hyperlink):
* lisp/arc-mode.el (archive-goto-file)
(archive-next-file-displayer):
* lisp/auth-source-pass.el (auth-source-pass-search)
(auth-source-pass--parse-data)
(auth-source-pass--find-match-many):
* lisp/autorevert.el (auto-revert-notify-rm-watch):
* lisp/buff-menu.el (Buffer-menu-unmark-all-buffers)
(Buffer-menu-group-by-root):
* lisp/calendar/parse-time.el (parse-iso8601-time-string):
* lisp/cedet/pulse.el (pulse-tick):
* lisp/comint.el (comint--fontify-input-ppss-flush-indirect)
(comint--intersect-regions):
* lisp/completion-preview.el (completion-preview--try-table)
(completion-preview--capf-wrapper, completion-preview--update):
* lisp/cus-edit.el (setopt--set)
(custom-dirlocals-maybe-update-cons, custom-dirlocals-validate):
* lisp/custom.el (load-theme):
* lisp/descr-text.el (describe-char):
* lisp/desktop.el (desktop--emacs-pid-running-p):
* lisp/dired-x.el (menu):
* lisp/dired.el (dired-font-lock-keywords)
(dired-insert-directory, dired--insert-disk-space, dired-mode):
* lisp/dnd.el (dnd-handle-multiple-urls):
* lisp/dom.el (dom-remove-attribute):
* lisp/emacs-lisp/byte-opt.el (byte-optimize-form-code-walker):
* lisp/emacs-lisp/bytecomp.el (bytecomp--custom-declare):
* lisp/emacs-lisp/comp-common.el (comp-function-type-spec):
* lisp/emacs-lisp/comp-cstr.el (comp--all-classes)
(comp-cstr-set-range-for-arithm, comp--cstr-union-1-no-mem)
(comp-cstr-intersection-no-mem, comp-cstr-fixnum-p)
(comp-cstr-type-p):
* lisp/emacs-lisp/comp-run.el (comp-subr-trampoline-install)
(native--compile-async):
* lisp/emacs-lisp/comp.el (comp--get-function-cstr)
(comp--function-pure-p, comp--intern-func-in-ctxt)
(comp--addr-to-bb-name, comp--emit-assume, comp--maybe-add-vmvar)
(comp--add-call-cstr, comp--compute-dominator-tree)
(comp--dom-tree-walker, comp--ssa-rename)
(comp--function-call-maybe-fold, comp--fwprop-call)
(comp--call-optim-func):
* lisp/emacs-lisp/edebug.el (edebug-global-prefix)
(edebug-remove-instrumentation):
* lisp/emacs-lisp/eieio.el (initialize-instance):
* lisp/emacs-lisp/ert-x.el (ert-resource-directory):
* lisp/emacs-lisp/ert.el (ert--expand-should-1)
(ert-test-location, ert-write-junit-test-report)
(ert-test--erts-test):
* lisp/emacs-lisp/icons.el (icon-complete-spec, icon-string)
(icons--create):
* lisp/emacs-lisp/lisp-mode.el (lisp--local-defform-body-p):
* lisp/emacs-lisp/loaddefs-gen.el
(loaddefs-generate--make-autoload)
(loaddefs-generate--parse-file):
* lisp/emacs-lisp/multisession.el
(multisession-edit-mode--revert, multisession-edit-value):
* lisp/emacs-lisp/package-vc.el (package-vc--read-archive-data)
(package-vc--version, package-vc--clone):
* lisp/emacs-lisp/package.el (package--reload-previously-loaded):
* lisp/emacs-lisp/pp.el (pp--insert-lisp):
* lisp/emacs-lisp/subr-x.el (add-display-text-property):
* lisp/emacs-lisp/tabulated-list.el (tabulated-list-print):
* lisp/emacs-lisp/timer.el (run-at-time):
* lisp/emacs-lisp/vtable.el (vtable-goto-table)
(vtable-goto-column, vtable-update-object, vtable--insert-line)
(vtable--compute-widths, vtable--make-keymap):
* lisp/emacs-lisp/warnings.el (display-warning):
* lisp/epa-file.el (epa-file-insert-file-contents):
* lisp/epa.el (epa-show-key):
* lisp/erc/erc-backend.el (erc--split-line, erc--conceal-prompt)
(PRIVMSG, erc--get-isupport-entry):
* lisp/erc/erc-button.el (erc-button-add-nickname-buttons)
(erc--button-next):
* lisp/erc/erc-common.el (erc--find-group):
* lisp/erc/erc-fill.el (erc-fill, erc-fill-static)
(erc-fill--wrap-escape-hidden-speaker)
(erc-fill--wrap-unmerge-on-date-stamp)
(erc-fill--wrap-massage-initial-message-post-clear)
(erc-fill-wrap, erc-fill--wrap-rejigger-region):
* lisp/erc/erc-goodies.el (erc--scrolltobottom-all)
(erc--keep-place-indicator-on-window-buffer-change)
(keep-place-indicator, erc--keep-place-indicator-adjust-on-clear)
(erc-keep-place-move, erc--command-indicator-display):
* lisp/erc/erc-ibuffer.el (erc-members):
* lisp/erc/erc-join.el (erc-join--remove-requested-channel)
(erc-autojoin--join):
* lisp/erc/erc-networks.el
(erc-networks--id-qualifying-init-parts, erc-networks--id-reload)
(erc-networks--id-ensure-comparable)
(erc-networks--reclaim-orphaned-target-buffers)
(erc-networks--server-select):
* lisp/erc/erc-nicks.el (erc-nicks-invert)
(erc-nicks--redirect-face-widget-link, erc-nicks--highlight)
(erc-nicks--highlight-button)
(erc-nicks--list-faces-help-button-action, erc-nicks-list-faces)
(erc-nicks-refresh, erc-nicks--colors-from-faces)
(erc-nicks--track-prioritize)
(erc-nicks--remember-face-for-track):
* lisp/erc/erc-notify.el (querypoll, erc--querypoll-get-next)
(erc--querypoll-on-352, erc--querypoll-send):
* lisp/erc/erc-sasl.el (erc-sasl--read-password):
* lisp/erc/erc-services.el
(erc-services-issue-ghost-and-retry-nick):
* lisp/erc/erc-speedbar.el (erc-speedbar--ensure, nickbar)
(erc-speedbar-toggle-nicknames-window-lock)
(erc-speedbar--compose-nicks-face):
* lisp/erc/erc-stamp.el (erc-stamp--recover-on-reconnect)
(erc-stamp-prefix-log-filter, erc--conceal-prompt)
(erc--insert-timestamp-left, erc-insert-timestamp-right)
(erc-stamp--defer-date-insertion-on-post-modify)
(erc-insert-timestamp-left-and-right)
(erc-stamp--redo-right-stamp-post-clear)
(erc-stamp--reset-on-clear, erc-stamp--dedupe-date-stamps):
* lisp/erc/erc-status-sidebar.el (bufbar)
(erc-status-sidebar-prefer-target-as-name)
(erc-status-sidebar-default-allsort, erc-status-sidebar-click):
* lisp/erc/erc-track.el (erc-track--shortened-names-get)
(erc-track--setup, erc-track--select-mode-line-face)
(erc-track-modified-channels, erc-track--collect-faces-in)
(erc-track--switch-buffer, erc-track--replace-killed-buffer):
* lisp/erc/erc-truncate.el (erc-truncate--setup)
(erc-truncate-buffer):
* lisp/erc/erc.el (erc--ensure-query-member)
(erc--ensure-query-members, erc--remove-channel-users-but)
(erc--cusr-change-status, erc--find-mode, erc--update-modules)
(erc-log-irc-protocol, erc--refresh-prompt)
(erc--restore-important-text-props)
(erc--order-text-properties-from-hash, erc-send-input-line)
(erc-cmd-IGNORE, erc--unignore-user, erc-cmd-QUERY)
(erc-cmd-BANLIST, erc--speakerize-nick)
(erc--format-speaker-input-message, erc-channel-receive-names)
(erc-send-current-line, erc-format-target-and/or-network)
(erc-kill-buffer-function, erc-restore-text-properties)
(erc--get-eq-comparable-cmd):
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias--which)
(eshell-maybe-replace-by-alias):
* lisp/eshell/em-glob.el (eshell-glob-convert):
* lisp/eshell/em-pred.el (eshell-pred-user-or-group)
(eshell-pred-file-time, eshell-pred-file-type)
(eshell-pred-file-mode, eshell-pred-file-links)
(eshell-pred-file-size):
* lisp/eshell/em-prompt.el (eshell-forward-paragraph)
(eshell-next-prompt):
* lisp/eshell/esh-arg.el (eshell-resolve-current-argument):
* lisp/eshell/esh-cmd.el (eshell-do-eval, eshell/which)
(eshell-plain-command--which, eshell-plain-command):
* lisp/eshell/esh-io.el (eshell-duplicate-handles)
(eshell-protect-handles, eshell-get-target, eshell-close-target):
* lisp/eshell/esh-proc.el (eshell-sentinel):
* lisp/eshell/esh-var.el (eshell-parse-variable-ref)
(eshell-get-variable, eshell-set-variable):
* lisp/faces.el (face-at-point):
* lisp/ffap.el (ffap-in-project):
* lisp/filenotify.el (file-notify--rm-descriptor):
* lisp/files-x.el (read-dir-locals-file)
(connection-local-update-profile-variables)
(connection-local-value):
* lisp/files.el (file-remote-p, abbreviate-file-name)
(set-auto-mode, hack-local-variables)
(revert-buffer-restore-read-only):
* lisp/find-dired.el (find-dired-sort-by-filename):
* lisp/font-lock.el (font-lock--filter-keywords):
* lisp/gnus/gnus-art.el (article-emojize-symbols):
* lisp/gnus/gnus-int.el (gnus-close-server):
* lisp/gnus/gnus-search.el (gnus-search-transform)
(gnus-search-indexed-parse-output, gnus-search-server-to-engine):
* lisp/gnus/gnus-sum.el (gnus-collect-urls, gnus-shorten-url):
* lisp/gnus/gnus.el (gnus-check-backend-function):
* lisp/gnus/message.el (message-send-mail):
* lisp/gnus/mml.el (mml-generate-mime, mml-insert-mime-headers):
* lisp/gnus/nnatom.el (nnatom--read-feed, nnatom--read-article)
(nnatom--read-article-or-group-authors, nnatom--read-publish)
(nnatom--read-update, nnatom--read-links):
* lisp/gnus/nnfeed.el (nnfeed--read-server, nnfeed--write-server)
(nnfeed--parse-feed, nnfeed--group-data, nnfeed-retrieve-article)
(nnfeed-retrieve-headers, nnfeed--print-part)
(nnfeed-request-article, nnfeed-request-group)
(nnfeed-request-list, nnfeed--group-description)
(nnfeed-request-group-description)
(nnfeed-request-list-newsgroups, nnfeed-request-rename-group):
* lisp/gnus/nnmh.el (nnmh-update-gnus-unreads):
* lisp/help-fns.el (help-find-source)
(help-fns--insert-menu-bindings, help-fns--mention-first-release)
(help-fns--mention-shortdoc-groups)
(help-fns--customize-variable-version)
(help-fns--face-custom-version-info, describe-mode):
* lisp/help-mode.el (help-make-xrefs):
* lisp/help.el (help-key-description, help--describe-command):
* lisp/hfy-cmap.el (htmlfontify-load-rgb-file):
* lisp/ibuf-ext.el (ibuffer-jump-to-filter-group)
(ibuffer-kill-filter-group, ibuffer-kill-line)
(ibuffer-save-filter-groups, ibuffer-save-filters, filename)
(basename, file-extension, ibuffer-diff-buffer-with-file-1)
(ibuffer-mark-by-file-name-regexp)
(ibuffer-mark-by-content-regexp):
* lisp/ibuf-macs.el (ibuffer-aif, ibuffer-awhen):
* lisp/ibuffer.el (ibuffer-mouse-toggle-mark)
(ibuffer-toggle-marks, ibuffer-mark-interactive)
(ibuffer-compile-format, process, ibuffer-map-lines):
* lisp/image.el (image--compute-map)
(image--compute-original-map):
* lisp/image/exif.el (exif-parse-buffer):
* lisp/image/image-converter.el (image-convert-p, image-convert)
(image-converter--find-converter):
* lisp/image/image-dired-util.el
(image-dired-file-name-at-point):
* lisp/image/image-dired.el (image-dired-track-original-file)
(image-dired--on-file-in-dired-buffer)
(image-dired--with-thumbnail-buffer)
(image-dired-jump-original-dired-buffer)
(image-dired--slideshow-step, image-dired-display-image):
* lisp/image/wallpaper.el (wallpaper--init-action-kill)
(wallpaper--find-setter, wallpaper--find-command)
(wallpaper--find-command-args, wallpaper--x-monitor-name):
* lisp/info-look.el (info-lookup-interactive-arguments)
(info-complete)::(:mode):
* lisp/info.el (info-pop-to-buffer, Info-read-node-name-1):
* lisp/international/emoji.el (emoji--adjust-displayable-1)
(emoji--add-recent):
* lisp/jsonrpc.el (jsonrpc--call-deferred)
(jsonrpc--process-sentinel, jsonrpc--remove):
* lisp/keymap.el (keymap-local-lookup):
* lisp/mail/emacsbug.el (report-emacs-bug-hook)
(submit-emacs-patch):
* lisp/mail/ietf-drums.el (ietf-drums-parse-addresses):
* lisp/mail/mailclient.el (mailclient-send-it):
* lisp/mail/rfc6068.el (rfc6068-parse-mailto-url):
* lisp/mail/undigest.el (rmail-digest-parse-mixed-mime):
* lisp/minibuffer.el (completion-metadata-get)
(completions--after-change)
(minibuffer-visible-completions--filter):
* lisp/net/browse-url.el (browse-url-url-at-point)
(browse-url-file-url, browse-url-emacs):
* lisp/net/dbus.el (dbus-byte-array-to-string)
(dbus-monitor-goto-serial):
* lisp/net/dictionary.el (dictionary-search):
* lisp/net/eww.el (eww--download-directory)
(eww-auto-rename-buffer, eww-open-in-new-buffer, eww-submit)
(eww-follow-link, eww-read-alternate-url)
(eww-copy-alternate-url):
* lisp/net/goto-addr.el (goto-address-at-point):
* lisp/net/mailcap.el (mailcap-mime-info):
* lisp/net/rcirc.el (rcirc, rcirc-connect, rcirc-send-string)
(rcirc-kill-buffer-hook, rcirc-print, rcirc-when)
(rcirc-color-attributes, rcirc-handler-NICK)
(rcirc-handler-TAGMSG, rcirc-handler-BATCH):
* lisp/net/shr.el (shr-descend, shr-adaptive-fill-function)
(shr-correct-dom-case, shr-tag-a):
* lisp/net/sieve.el (sieve-manage-quit):
* lisp/outline.el (outline-cycle-buffer):
* lisp/pcmpl-git.el (pcmpl-git--tracked-file-predicate):
* lisp/proced.el (proced-auto-update-timer):
* lisp/progmodes/bug-reference.el
(bug-reference-try-setup-from-vc):
* lisp/progmodes/c-ts-common.el (c-ts-common--fill-paragraph):
* lisp/progmodes/c-ts-mode.el (c-ts-mode--preproc-offset)
(c-ts-mode--anchor-prev-sibling, c-ts-mode-indent-defun):
* lisp/progmodes/compile.el (compilation-error-properties)
(compilation-find-file-1):
* lisp/progmodes/eglot.el (eglot--check-object)
(eglot--read-server, eglot-upgrade-eglot)
(eglot-handle-notification, eglot--CompletionParams)
(eglot-completion-at-point, eglot--sig-info)
(eglot-register-capability):
* lisp/progmodes/elisp-mode.el
(emacs-lisp-native-compile-and-load)
(elisp-eldoc-var-docstring-with-value):
* lisp/progmodes/erts-mode.el (erts-mode--goto-start-of-test):
* lisp/progmodes/flymake.el (flymake--update-eol-overlays)
(flymake-eldoc-function):
* lisp/progmodes/gdb-mi.el (gdb-breakpoints-list-handler-custom)
(gdb-frame-handler):
* lisp/progmodes/go-ts-mode.el (go-ts-mode-docstring)
(go-ts-mode--comment-on-previous-line-p)
(go-ts-mode--get-test-regexp-at-point)
(go-ts-mode-test-this-file):
* lisp/progmodes/grep.el (lgrep, rgrep-default-command)
(grep-file-at-point):
* lisp/progmodes/perl-mode.el (perl--end-of-format-p):
* lisp/progmodes/php-ts-mode.el
(php-ts-mode--anchor-prev-sibling, php-ts-mode--indent-defun):
* lisp/progmodes/project.el (project--other-place-command)
(project--find-default-from, project--transplant-file-name)
(project-prefixed-buffer-name, project--remove-from-project-list)
(project-prompt-project-name, project-remember-projects-under)
(project--switch-project-command)
(project-uniquify-dirname-transform, project-mode-line-format):
* lisp/progmodes/python.el
(python-font-lock-keywords-maximum-decoration)
(python--treesit-fontify-union-types)
(python-shell-get-process-name, python-shell-restart)
(python-shell-completion-at-point, python-ffap-module-path)
(python-util-comint-end-of-output-p, python--import-sources)
(python-add-import, python-remove-import, python-fix-imports):
* lisp/progmodes/xref.el (xref--add-log-current-defun):
* lisp/repeat.el (repeat-echo-message-string):
* lisp/saveplace.el (save-place-dired-hook):
* lisp/server.el (server-save-buffers-kill-terminal):
* lisp/shadowfile.el (shadow-make-fullname)
(shadow-contract-file-name, shadow-define-literal-group):
* lisp/shell.el (shell-highlight-undef-mode):
* lisp/simple.el (command-completion-using-modes-p)
(command-execute, file-user-uid, file-group-gid)
(first-completion, last-completion, switch-to-completions):
* lisp/startup.el (startup--load-user-init-file):
* lisp/tab-line.el (tab-line-tabs-buffer-group-by-project):
* lisp/tar-mode.el (tar-goto-file, tar-next-file-displayer):
* lisp/term/android-win.el (android-encode-select-string)
(gui-backend-set-selection):
* lisp/term/haiku-win.el (haiku-dnd-convert-string)
(haiku-select-encode-xstring, haiku-select-encode-utf-8-string):
* lisp/textmodes/emacs-news-mode.el (emacs-news--buttonize):
* lisp/textmodes/ispell.el (ispell-completion-at-point):
* lisp/textmodes/sgml-mode.el (sgml-validate)
(html-mode--complete-at-point):
* lisp/textmodes/tex-mode.el (tex-recenter-output-buffer)
(xref-backend-references):
* lisp/thingatpt.el (thing-at-point-file-at-point)
(thing-at-point-face-at-point):
* lisp/thread.el (thread-list--get-status):
* lisp/time.el (world-clock-copy-time-as-kill, world-clock):
* lisp/touch-screen.el (touch-screen-handle-touch):
* lisp/treesit.el (treesit-language-at, treesit-node-at)
(treesit-node-on, treesit-buffer-root-node)
(treesit-node-field-name, treesit-local-parsers-at)
(treesit-local-parsers-on, treesit--cleanup-local-range-overlays)
(treesit-font-lock-recompute-features)
(treesit-font-lock-fontify-region, treesit-transpose-sexps)
(treesit-add-log-current-defun, treesit-major-mode-setup)
(treesit--explorer-refresh, treesit-install-language-grammar):
* lisp/url/url.el (url-retrieve-synchronously):
* lisp/vc/smerge-mode.el (smerge-diff):
* lisp/vc/vc-dir.el (vc-dir):
* lisp/vc/vc-dispatcher.el (vc-do-async-command):
* lisp/vc/vc-git.el (vc-git-dir--branch-headers)
(vc-git-dir--stash-headers, vc-git--log-edit-summary-check)
(vc-git-stash-list):
* lisp/vc/vc.el (vc-responsible-backend, vc-buffer-sync-fileset)
(vc-clone):
* lisp/visual-wrap.el (visual-wrap--apply-to-line):
* lisp/wid-edit.el (widget-text)
(widget-editable-list-insert-before):
* lisp/window-tool-bar.el
(window-tool-bar--keymap-entry-to-string):
* lisp/window.el (display-buffer, display-buffer-full-frame)
(window-point-context-set, window-point-context-use)
(window-point-context-use-default-function):
* lisp/xdg.el (xdg-current-desktop):
* lisp/xwidget.el (xwidget-webkit-callback):
* lisp/yank-media.el (yank-media--get-selection)
(yank-media-types):
* test/lisp/comint-tests.el
(comint-tests/test-password-function):
* test/lisp/completion-preview-tests.el
(completion-preview-tests--capf):
* test/lisp/cus-edit-tests.el (with-cus-edit-test):
* test/lisp/erc/erc-scenarios-base-local-modules.el
(-phony-sblm-):
* test/lisp/erc/erc-scenarios-stamp.el
(erc-scenarios-stamp--on-post-modify):
* test/lisp/erc/erc-services-tests.el
(erc-services-tests--asp-parse-entry):
* test/lisp/erc/erc-tests.el (erc-modules--internal-property)
(erc--find-mode, erc-tests--update-modules):
* test/lisp/erc/resources/erc-d/erc-d-i.el
(erc-d-i--parse-message):
* test/lisp/erc/resources/erc-d/erc-d-t.el
(erc-d-t-kill-related-buffers, erc-d-t-with-cleanup):
* test/lisp/erc/resources/erc-d/erc-d-tests.el
(erc-d-i--parse-message--irc-parser-tests):
* test/lisp/erc/resources/erc-d/erc-d-u.el
(erc-d-u--read-exchange-slowly):
* test/lisp/erc/resources/erc-d/erc-d.el (erc-d--expire)
(erc-d--finalize-done, erc-d--command-handle-all):
* test/lisp/erc/resources/erc-scenarios-common.el
(erc-scenarios-common-with-cleanup):
* test/lisp/erc/resources/erc-tests-common.el
(erc-tests--common-display-message)
(erc-tests-common-create-subprocess):
* test/lisp/ibuffer-tests.el (ibuffer-test-Bug25058):
* test/lisp/international/mule-tests.el
(mule-cmds-tests--ucs-names-missing-names):
* test/lisp/progmodes/python-tests.el
(python-tests-get-shell-interpreter)
(python-tests--get-interpreter-info):
* test/lisp/progmodes/ruby-ts-mode-tests.el
(ruby-ts-resource-file):
* test/lisp/replace-tests.el (replace-tests-with-undo):
* test/src/emacs-tests.el (emacs-tests--seccomp-debug):
* test/src/process-tests.el (process-tests--emacs-command)
(process-tests--emacs-binary, process-tests--dump-file):
* test/src/treesit-tests.el (treesit--ert-test-defun-navigation):
Replace use of the now-obsolete if-let and when-let.
2024-10-24 16:50:07 +08:00
|
|
|
(if-let* ((buf (comint-indirect-buffer t)))
|
2022-09-09 20:12:26 +02:00
|
|
|
(with-current-buffer buf
|
|
|
|
(funcall setup))
|
|
|
|
(add-hook 'comint-indirect-setup-hook setup nil t)))
|
|
|
|
(t (funcall setup))))
|
|
|
|
|
2022-09-30 20:28:15 +02:00
|
|
|
(add-hook 'comint-fontify-input-mode-hook
|
2022-09-11 12:59:02 +02:00
|
|
|
#'shell-highlight-undef-mode-restart nil t))
|
2022-09-09 20:12:26 +02:00
|
|
|
|
|
|
|
(font-lock-flush))
|
|
|
|
|
2022-09-11 12:59:02 +02:00
|
|
|
(defun shell-highlight-undef-mode-restart ()
|
|
|
|
"If `shell-highlight-undef-mode' is on, restart it.
|
|
|
|
`shell-highlight-undef-mode' performs its setup differently
|
2022-09-30 20:28:15 +02:00
|
|
|
depending on `comint-fontify-input-mode'. It's useful to call
|
|
|
|
this function when switching `comint-fontify-input-mode' in order
|
|
|
|
to make `shell-highlight-undef-mode' redo its setup."
|
2022-09-09 20:12:26 +02:00
|
|
|
(when shell-highlight-undef-mode
|
|
|
|
(shell-highlight-undef-mode 1)))
|
|
|
|
|
2025-03-06 12:04:57 +01:00
|
|
|
;;; Bookmark support:
|
|
|
|
|
|
|
|
(declare-function bookmark-prop-get "bookmark" (bookmark prop))
|
|
|
|
|
2025-03-06 12:52:51 +01:00
|
|
|
(defcustom shell-bookmark-name-function
|
|
|
|
#'shell-bookmark-name-from-default-directory
|
2025-03-06 12:04:57 +01:00
|
|
|
"Function to generate a shell bookmark name.
|
2025-03-06 12:52:51 +01:00
|
|
|
The default is `shell-bookmark-name-from-default-directory', which see."
|
2025-03-06 12:04:57 +01:00
|
|
|
:group 'shell
|
|
|
|
:type `(choice (function-item ,#'shell-bookmark-name-from-default-directory)
|
|
|
|
(function-item ,#'shell-bookmark-name-from-buffer-name)
|
|
|
|
function)
|
|
|
|
:version "31.1")
|
|
|
|
|
|
|
|
(defun shell-bookmark-name-from-default-directory ()
|
|
|
|
"Return a `shell-mode' bookmark name based on `default-directory'.
|
2025-03-06 12:52:51 +01:00
|
|
|
Return \"shell-\" appended with the final file name component of the
|
|
|
|
buffer's `default-directory'."
|
2025-03-06 12:04:57 +01:00
|
|
|
(format "shell-%s"
|
|
|
|
(file-name-nondirectory
|
|
|
|
(directory-file-name
|
|
|
|
(file-name-directory default-directory)))))
|
|
|
|
|
|
|
|
(defun shell-bookmark-name-from-buffer-name ()
|
2025-03-06 12:52:51 +01:00
|
|
|
"Return a `shell-mode' bookmark name based on buffer name.
|
2025-03-06 12:04:57 +01:00
|
|
|
Return `buffer-name' stripped of its count suffix; e.g., \"*shell*<2>\",
|
|
|
|
if adorned by `rename-uniquely', which see."
|
|
|
|
(replace-regexp-in-string "<[[:digit:]]+>\\'" "" (buffer-name)))
|
|
|
|
|
|
|
|
(defvar shell-bookmark-defaults-function #'shell-bookmark-defaults
|
|
|
|
"Function to generate a list of default shell bookmark names.
|
|
|
|
This list is used by `bookmark-set' and prompted by
|
|
|
|
`read-from-minibuffer'.")
|
|
|
|
|
|
|
|
(defun shell-bookmark-defaults ()
|
|
|
|
"Return bookmark name options for the current `shell-mode' buffer."
|
|
|
|
(list
|
|
|
|
(funcall shell-bookmark-name-function)
|
|
|
|
(buffer-name)
|
|
|
|
default-directory))
|
|
|
|
|
|
|
|
(defun shell-bookmark-make-record ()
|
|
|
|
"Create a bookmark record for the current `shell-mode' buffer.
|
|
|
|
Handle both local and remote shell buffers.
|
2025-03-06 12:52:51 +01:00
|
|
|
For ad-hoc multi-hop remote connections, see Info node
|
|
|
|
`(tramp)Ad-hoc multi-hops'."
|
2025-03-06 12:04:57 +01:00
|
|
|
(let ((bookmark-shell-file-name
|
|
|
|
(or (connection-local-value shell-file-name) sh-shell-file)))
|
|
|
|
`((defaults . ,(funcall shell-bookmark-defaults-function))
|
|
|
|
(location . ,default-directory)
|
|
|
|
(shell-file-name . ,bookmark-shell-file-name)
|
|
|
|
(handler . shell-bookmark-jump))))
|
|
|
|
|
|
|
|
(defvar shell-bookmark-jump-non-essential nil
|
|
|
|
"If non-nil, new remote connections are inhibited in shell-bookmark-jump.
|
|
|
|
This is useful when loading a session via `desktop-read' or another
|
|
|
|
session-management package.")
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun shell-bookmark-jump (bookmark)
|
|
|
|
"Default BOOKMARK handler for shell buffers.
|
|
|
|
Create a shell buffer with its `default-directory', shell process, and
|
|
|
|
buffer name from the bookmark. If there is an existing shell buffer of
|
|
|
|
the same name, default `shell-mode' behavior is to reuse that buffer.
|
|
|
|
|
|
|
|
For a remote shell `default-directory' will be the remote file name.
|
|
|
|
Remote shell buffers reuse existing connections that match the remote
|
2025-03-06 12:52:51 +01:00
|
|
|
file name, or may prompt you to create a new connection. For ad-hoc
|
|
|
|
multi-hop remote connections, see Info node `(tramp)Ad-hoc multi-hops'.
|
2025-03-06 12:04:57 +01:00
|
|
|
|
|
|
|
If called with a single \\[universal-argument] prefix, a new shell
|
|
|
|
buffer will be created if there is an existing buffer with the same
|
|
|
|
name. The new buffer name is made unique using `rename-uniquely', which
|
|
|
|
see.
|
|
|
|
|
|
|
|
If called with a double \\[universal-argument] prefix, new remote
|
|
|
|
connections are inhibited, though an existing connection will be reused.
|
|
|
|
You can make a remote connection manually by reloading the buffer using
|
|
|
|
\\[find-alternate-file] or create a new shell using \\[shell].
|
|
|
|
|
|
|
|
If called with a triple \\[universal-argument] prefix, a new buffer will
|
|
|
|
be created if necessary, and new remote connections are inhibited."
|
|
|
|
(let* ((bookmark-default-directory (bookmark-prop-get bookmark 'location))
|
|
|
|
(default-directory bookmark-default-directory)
|
|
|
|
(explicit-shell-file-name (bookmark-prop-get bookmark 'shell-file-name))
|
|
|
|
(prefix-arg (prefix-numeric-value current-prefix-arg))
|
|
|
|
(maybe-new-shell (or (= 4 prefix-arg) (= 64 prefix-arg)))
|
|
|
|
(non-essential (or shell-bookmark-jump-non-essential
|
|
|
|
(= 16 prefix-arg) (= 64 prefix-arg)))
|
|
|
|
(shell-buffer-name (car bookmark))
|
|
|
|
(shell-buffer-name (if (and maybe-new-shell
|
|
|
|
(comint-check-proc shell-buffer-name))
|
|
|
|
(generate-new-buffer-name shell-buffer-name)
|
|
|
|
shell-buffer-name)))
|
|
|
|
;; Handle a local shell, a remote shell with an existing
|
|
|
|
;; connection, or a remote shell needing a connection and new
|
|
|
|
;; connections not inhibited.
|
|
|
|
(if (or (not (file-remote-p default-directory))
|
|
|
|
(file-remote-p default-directory nil 'connected)
|
|
|
|
(and (not non-essential)
|
|
|
|
(not (file-remote-p default-directory nil 'connected))))
|
|
|
|
(shell shell-buffer-name)
|
|
|
|
;; Handle a remote shell with no matching active connection and if
|
|
|
|
;; new connections are inhibited.
|
|
|
|
(let* ((file-name-handler-alist nil)
|
|
|
|
;; Ignore file-name-handler-alist to guard
|
|
|
|
;; abbreviate-file-name, et.al., which are remote aware.
|
|
|
|
;; The macro without-remote-files is insufficient for this
|
|
|
|
;; case.
|
|
|
|
(shell-buffer
|
|
|
|
(shell shell-buffer-name)))
|
|
|
|
(with-current-buffer shell-buffer
|
|
|
|
;; Allow reloading or M-x shell to attempt a remote connection.
|
|
|
|
(setq default-directory bookmark-default-directory)
|
|
|
|
(setq list-buffers-directory bookmark-default-directory)
|
|
|
|
;; Inhibit features that may cause remote connection attempts.
|
|
|
|
;; These settings revert when the user reloads the buffer.
|
|
|
|
(dirtrack-mode -1)
|
|
|
|
(shell-dirtrack-mode -1)
|
|
|
|
(delq (assoc "7" ansi-osc-handlers) ; ansi-osc-directory-tracker
|
|
|
|
ansi-osc-handlers))))))
|
|
|
|
(put #'shell-bookmark-jump 'bookmark-handler-type "Shell")
|
|
|
|
(put #'shell-bookmark-jump 'bookmark-inhibit 'insert)
|
|
|
|
|
1992-05-30 21:11:25 +00:00
|
|
|
(provide 'shell)
|
|
|
|
|
|
|
|
;;; shell.el ends here
|