2013-09-12 16:15:53 -04:00
|
|
|
;;; esh-var.el --- handling of variables -*- lexical-binding:t -*-
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2024-01-02 09:47:10 +08:00
|
|
|
;; Copyright (C) 1999-2024 Free Software Foundation, Inc.
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2000-10-16 12:27:09 +00:00
|
|
|
;; Author: John Wiegley <johnw@gnu.org>
|
|
|
|
|
2000-06-23 05:24:10 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 03:36:21 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2000-06-23 05:24:10 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 03:36:21 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2000-06-23 05:24:10 +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.
|
|
|
|
|
|
|
|
;; 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/>.
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; These are the possible variable interpolation syntaxes. Also keep
|
|
|
|
;; in mind that if an argument looks like a number, it will be
|
|
|
|
;; converted to a number. This is not significant when invoking
|
|
|
|
;; external commands, but it's important when calling Lisp functions.
|
|
|
|
;;
|
|
|
|
;; $VARIABLE
|
|
|
|
;;
|
|
|
|
;; Interval the value of an environment variable, or a Lisp variable
|
|
|
|
;;
|
|
|
|
;; $ALSO-VAR
|
|
|
|
;;
|
2008-02-05 12:07:11 +00:00
|
|
|
;; "-" is a valid part of a variable name.
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-02-27 13:20:51 -08:00
|
|
|
;; $\"MYVAR\"-TOO
|
|
|
|
;; $'MYVAR'-TOO
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
|
|
|
;; Only "MYVAR" is part of the variable name in this case.
|
|
|
|
;;
|
|
|
|
;; $(lisp)
|
|
|
|
;;
|
2021-09-19 12:45:56 +02:00
|
|
|
;; Returns result of Lisp evaluation. Note: Used alone like this, it
|
2000-06-23 05:24:10 +00:00
|
|
|
;; is identical to just saying (lisp); but with the variable expansion
|
|
|
|
;; form, the result may be interpolated a larger string, such as
|
|
|
|
;; '$(lisp)/other'.
|
|
|
|
;;
|
|
|
|
;; ${command}
|
|
|
|
;;
|
|
|
|
;; Returns the value of an eshell subcommand. See the note above
|
|
|
|
;; regarding Lisp evaluations.
|
|
|
|
;;
|
2022-02-27 13:20:51 -08:00
|
|
|
;; $<command>
|
|
|
|
;;
|
|
|
|
;; Evaluates an eshell subcommand, redirecting the output to a
|
|
|
|
;; temporary file, and returning the file name.
|
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; $EXPR[10]
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; Return the 10th element of $EXPR, which can be any dollar
|
|
|
|
;; expression. If $EXPR's value is a string, it will be split in
|
|
|
|
;; order to make it a list. The splitting will occur at whitespace.
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; $EXPR[10 20]
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; As above, but instead of returning a single element, it now returns a
|
|
|
|
;; list of two elements.
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; $EXPR[: 10]
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; Like $EXPR[10], except that splitting occurs at the colon now.
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; $EXPR["\\\\" 10]
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
|
|
|
;; Separate on backslash characters. Actually, the first argument --
|
2022-03-01 18:53:42 -08:00
|
|
|
;; if it doesn't have the form of a number -- can be any regular
|
|
|
|
;; expression. So to split on numbers, use '$EXPR["[0-9]+" 10 20]'.
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; $EXPR[hello]
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; Calls `assoc' on $EXPR with 'hello', expecting it to be an alist.
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; $#EXPR
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-03-01 18:36:08 -08:00
|
|
|
;; Returns the length of the value of $EXPR. This could also be
|
|
|
|
;; done using the `length' Lisp function.
|
2000-06-23 05:24:10 +00:00
|
|
|
;;
|
2022-11-08 22:49:23 -08:00
|
|
|
;; $@EXPR
|
|
|
|
;;
|
|
|
|
;; Splices the value of $EXPR in-place into the current list of
|
|
|
|
;; arguments. This is analogous to the `,@' token in Elisp
|
|
|
|
;; backquotes, and works as if the user typed '$EXPR[0] $EXPR[1]
|
|
|
|
;; ... $EXPR[N]'.
|
|
|
|
;;
|
2000-06-23 05:24:10 +00:00
|
|
|
;; There are also a few special variables defined by Eshell. '$$' is
|
|
|
|
;; the value of the last command (t or nil, in the case of an external
|
|
|
|
;; command). This makes it possible to chain results:
|
|
|
|
;;
|
|
|
|
;; /tmp $ echo /var/spool/mail/johnw
|
|
|
|
;; /var/spool/mail/johnw
|
|
|
|
;; /tmp $ dirname $$
|
|
|
|
;; /var/spool/mail/
|
|
|
|
;; /tmp $ cd $$
|
|
|
|
;; /var/spool/mail $
|
|
|
|
;;
|
|
|
|
;; '$_' refers to the last argument of the last command. And $?
|
|
|
|
;; contains the exit code of the last command (0 or 1 for Lisp
|
|
|
|
;; functions, based on successful completion).
|
|
|
|
|
2009-01-22 06:33:06 +00:00
|
|
|
;;; Code:
|
|
|
|
|
Silence many eshell compilation warnings
* lisp/eshell/em-tramp.el: Adjust requires.
(eshell-parse-command): Autoload.
* lisp/eshell/em-xtra.el: Adjust requires.
(eshell-parse-command): Autoload.
* lisp/eshell/esh-ext.el: Adjust requires.
(eshell-parse-command, eshell-close-handles): Autoload.
* lisp/eshell/esh-io.el: Adjust requires.
(eshell-output-filter): Autoload.
* lisp/eshell/esh-util.el: No need to load tramp when compiling.
(tramp-file-name-structure, ange-ftp-ls, ange-ftp-file-modtime): Declare.
(eshell-parse-ange-ls): Require ange-ftp and tramp.
* lisp/eshell/em-alias.el, lisp/eshell/em-banner.el, lisp/eshell/em-basic.el:
* lisp/eshell/em-cmpl.el, lisp/eshell/em-glob.el, lisp/eshell/em-pred.el:
* lisp/eshell/em-prompt.el, lisp/eshell/em-rebind.el, lisp/eshell/em-smart.el:
* lisp/eshell/em-term.el, lisp/eshell/esh-arg.el, lisp/eshell/esh-mode.el:
* lisp/eshell/esh-opt.el, lisp/eshell/esh-proc.el:
* lisp/eshell/esh-var.el: Adjust requires.
* lisp/eshell/eshell.el: Do not require esh-util twice.
(eshell-add-input-to-history): Declare.
(eshell-command): Check history module is active before using it.
2013-05-22 21:57:27 -07:00
|
|
|
(require 'esh-util)
|
|
|
|
(require 'esh-cmd)
|
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
|
|
|
(require 'esh-opt)
|
Eshell: Try to untangle the dependencies; move 'provide's to the end
* lisp/eshell/esh-arg.el: Move defsubst and vars before first use.
Don't require `esh-mode but esh-util instead.
* lisp/eshell/esh-cmd.el: Require esh-module and esh-io.
* lisp/eshell/esh-ext.el: Don't require esh-proc nor esh-cmd.
(eshell-external-command): Require esh-proc for
eshell-gather-process-output.
* lisp/eshell/esh-mode.el: Don't require esh-io nor esh-var, but
require esh-arg.
(eshell-directory-name): Move from eshell.el.
* lisp/eshell/esh-module.el: Don't require eshell.
* lisp/eshell/esh-opt.el: Don't require esh-ext at top-level.
(eshell--do-opts, eshell-show-usage): Require it here instead.
* lisp/eshell/esh-proc.el: Don't require esh-cmd, but require esh-io.
(eshell-reset-after-proc, eshell-record-process-object)
(eshell-gather-process-output, eshell-send-eof-to-process):
Require esh-mode and esh-var here.
* lisp/eshell/esh-var.el: Require esh-module, esh-arg, and esh-io.
* lisp/eshell/eshell.el: Require esh-module, esh-proc, esh-io, and esh-cmd.
But don't require esh-mode.
(eshell-directory-name): Move to esh-mode.
(eshell-return-exits-minibuffer): Don't bind 'return' and 'M-return'
since we already bind RET and M-RET.
2019-04-08 14:28:34 -04:00
|
|
|
(require 'esh-module)
|
|
|
|
(require 'esh-arg)
|
|
|
|
(require 'esh-io)
|
Silence many eshell compilation warnings
* lisp/eshell/em-tramp.el: Adjust requires.
(eshell-parse-command): Autoload.
* lisp/eshell/em-xtra.el: Adjust requires.
(eshell-parse-command): Autoload.
* lisp/eshell/esh-ext.el: Adjust requires.
(eshell-parse-command, eshell-close-handles): Autoload.
* lisp/eshell/esh-io.el: Adjust requires.
(eshell-output-filter): Autoload.
* lisp/eshell/esh-util.el: No need to load tramp when compiling.
(tramp-file-name-structure, ange-ftp-ls, ange-ftp-file-modtime): Declare.
(eshell-parse-ange-ls): Require ange-ftp and tramp.
* lisp/eshell/em-alias.el, lisp/eshell/em-banner.el, lisp/eshell/em-basic.el:
* lisp/eshell/em-cmpl.el, lisp/eshell/em-glob.el, lisp/eshell/em-pred.el:
* lisp/eshell/em-prompt.el, lisp/eshell/em-rebind.el, lisp/eshell/em-smart.el:
* lisp/eshell/em-term.el, lisp/eshell/esh-arg.el, lisp/eshell/esh-mode.el:
* lisp/eshell/esh-opt.el, lisp/eshell/esh-proc.el:
* lisp/eshell/esh-var.el: Adjust requires.
* lisp/eshell/eshell.el: Do not require esh-util twice.
(eshell-add-input-to-history): Declare.
(eshell-command): Check history module is active before using it.
2013-05-22 21:57:27 -07:00
|
|
|
|
|
|
|
(require 'pcomplete)
|
2000-06-23 05:24:10 +00:00
|
|
|
(require 'ring)
|
|
|
|
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
(defvar-local eshell-inside-emacs (format "%s,eshell" emacs-version)
|
2022-07-03 20:05:29 -07:00
|
|
|
"Value for the `INSIDE_EMACS' environment variable.")
|
|
|
|
|
2007-12-05 07:09:53 +00:00
|
|
|
(defgroup eshell-var nil
|
Go back to grave quoting in source-code docstrings etc.
This reverts almost all my recent changes to use curved quotes
in docstrings and/or strings used for error diagnostics.
There are a few exceptions, e.g., Bahá’í proper names.
* admin/unidata/unidata-gen.el (unidata-gen-table):
* lisp/abbrev.el (expand-region-abbrevs):
* lisp/align.el (align-region):
* lisp/allout.el (allout-mode, allout-solicit-alternate-bullet)
(outlineify-sticky):
* lisp/apropos.el (apropos-library):
* lisp/bookmark.el (bookmark-default-annotation-text):
* lisp/button.el (button-category-symbol, button-put)
(make-text-button):
* lisp/calc/calc-aent.el (math-read-if, math-read-factor):
* lisp/calc/calc-embed.el (calc-do-embedded):
* lisp/calc/calc-ext.el (calc-user-function-list):
* lisp/calc/calc-graph.el (calc-graph-show-dumb):
* lisp/calc/calc-help.el (calc-describe-key)
(calc-describe-thing, calc-full-help):
* lisp/calc/calc-lang.el (calc-c-language)
(math-parse-fortran-vector-end, math-parse-tex-sum)
(math-parse-eqn-matrix, math-parse-eqn-prime)
(calc-yacas-language, calc-maxima-language, calc-giac-language)
(math-read-giac-subscr, math-read-math-subscr)
(math-read-big-rec, math-read-big-balance):
* lisp/calc/calc-misc.el (calc-help, report-calc-bug):
* lisp/calc/calc-mode.el (calc-auto-why, calc-save-modes)
(calc-auto-recompute):
* lisp/calc/calc-prog.el (calc-fix-token-name)
(calc-read-parse-table-part, calc-user-define-invocation)
(math-do-arg-check):
* lisp/calc/calc-store.el (calc-edit-variable):
* lisp/calc/calc-units.el (math-build-units-table-buffer):
* lisp/calc/calc-vec.el (math-read-brackets):
* lisp/calc/calc-yank.el (calc-edit-mode):
* lisp/calc/calc.el (calc, calc-do, calc-user-invocation):
* lisp/calendar/appt.el (appt-display-message):
* lisp/calendar/diary-lib.el (diary-check-diary-file)
(diary-mail-entries, diary-from-outlook):
* lisp/calendar/icalendar.el (icalendar-export-region)
(icalendar--convert-float-to-ical)
(icalendar--convert-date-to-ical)
(icalendar--convert-ical-to-diary)
(icalendar--convert-recurring-to-diary)
(icalendar--add-diary-entry):
* lisp/calendar/time-date.el (format-seconds):
* lisp/calendar/timeclock.el (timeclock-mode-line-display)
(timeclock-make-hours-explicit, timeclock-log-data):
* lisp/calendar/todo-mode.el (todo-prefix, todo-delete-category)
(todo-item-mark, todo-check-format)
(todo-insert-item--next-param, todo-edit-item--next-key)
(todo-mode):
* lisp/cedet/ede/pmake.el (ede-proj-makefile-insert-dist-rules):
* lisp/cedet/mode-local.el (describe-mode-local-overload)
(mode-local-print-binding, mode-local-describe-bindings-2):
* lisp/cedet/semantic/complete.el (semantic-displayor-show-request):
* lisp/cedet/srecode/srt-mode.el (srecode-macro-help):
* lisp/cus-start.el (standard):
* lisp/cus-theme.el (describe-theme-1):
* lisp/custom.el (custom-add-dependencies, custom-check-theme)
(custom--sort-vars-1, load-theme):
* lisp/descr-text.el (describe-text-properties-1, describe-char):
* lisp/dired-x.el (dired-do-run-mail):
* lisp/dired.el (dired-log):
* lisp/emacs-lisp/advice.el (ad-read-advised-function)
(ad-read-advice-class, ad-read-advice-name, ad-enable-advice)
(ad-disable-advice, ad-remove-advice, ad-set-argument)
(ad-set-arguments, ad--defalias-fset, ad-activate)
(ad-deactivate):
* lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand)
(byte-compile-unfold-lambda, byte-optimize-form-code-walker)
(byte-optimize-while, byte-optimize-apply):
* lisp/emacs-lisp/byte-run.el (defun, defsubst):
* lisp/emacs-lisp/bytecomp.el (byte-compile-lapcode)
(byte-compile-log-file, byte-compile-format-warn)
(byte-compile-nogroup-warn, byte-compile-arglist-warn)
(byte-compile-cl-warn)
(byte-compile-warn-about-unresolved-functions)
(byte-compile-file, byte-compile--declare-var)
(byte-compile-file-form-defmumble, byte-compile-form)
(byte-compile-normal-call, byte-compile-check-variable)
(byte-compile-variable-ref, byte-compile-variable-set)
(byte-compile-subr-wrong-args, byte-compile-setq-default)
(byte-compile-negation-optimizer)
(byte-compile-condition-case--old)
(byte-compile-condition-case--new, byte-compile-save-excursion)
(byte-compile-defvar, byte-compile-autoload)
(byte-compile-lambda-form)
(byte-compile-make-variable-buffer-local, display-call-tree)
(batch-byte-compile):
* lisp/emacs-lisp/cconv.el (cconv-convert, cconv--analyze-use):
* lisp/emacs-lisp/chart.el (chart-space-usage):
* lisp/emacs-lisp/check-declare.el (check-declare-scan)
(check-declare-warn, check-declare-file)
(check-declare-directory):
* lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine)
(checkdoc-message-text-engine):
* lisp/emacs-lisp/cl-extra.el (cl-parse-integer)
(cl--describe-class):
* lisp/emacs-lisp/cl-generic.el (cl-defgeneric)
(cl--generic-describe, cl-generic-generalizers):
* lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause, cl-tagbody)
(cl-symbol-macrolet):
* lisp/emacs-lisp/cl.el (cl-unload-function, flet):
* lisp/emacs-lisp/copyright.el (copyright)
(copyright-update-directory):
* lisp/emacs-lisp/edebug.el (edebug-read-list):
* lisp/emacs-lisp/eieio-base.el (eieio-persistent-read):
* lisp/emacs-lisp/eieio-core.el (eieio--slot-override)
(eieio-oref):
* lisp/emacs-lisp/eieio-opt.el (eieio-help-constructor):
* lisp/emacs-lisp/eieio-speedbar.el:
(eieio-speedbar-child-make-tag-lines)
(eieio-speedbar-child-description):
* lisp/emacs-lisp/eieio.el (defclass, change-class):
* lisp/emacs-lisp/elint.el (elint-file, elint-get-top-forms)
(elint-init-form, elint-check-defalias-form)
(elint-check-let-form):
* lisp/emacs-lisp/ert.el (ert-get-test, ert-results-mode-menu)
(ert-results-pop-to-backtrace-for-test-at-point)
(ert-results-pop-to-messages-for-test-at-point)
(ert-results-pop-to-should-forms-for-test-at-point)
(ert-describe-test):
* lisp/emacs-lisp/find-func.el (find-function-search-for-symbol)
(find-function-library):
* lisp/emacs-lisp/generator.el (iter-yield):
* lisp/emacs-lisp/gv.el (gv-define-simple-setter):
* lisp/emacs-lisp/lisp-mnt.el (lm-verify):
* lisp/emacs-lisp/macroexp.el (macroexp--obsolete-warning):
* lisp/emacs-lisp/map-ynp.el (map-y-or-n-p):
* lisp/emacs-lisp/nadvice.el (advice--make-docstring)
(advice--make, define-advice):
* lisp/emacs-lisp/package-x.el (package-upload-file):
* lisp/emacs-lisp/package.el (package-version-join)
(package-disabled-p, package-activate-1, package-activate)
(package--download-one-archive)
(package--download-and-read-archives)
(package-compute-transaction, package-install-from-archive)
(package-install, package-install-selected-packages)
(package-delete, package-autoremove, describe-package-1)
(package-install-button-action, package-delete-button-action)
(package-menu-hide-package, package-menu--list-to-prompt)
(package-menu--perform-transaction)
(package-menu--find-and-notify-upgrades):
* lisp/emacs-lisp/pcase.el (pcase-exhaustive, pcase--u1):
* lisp/emacs-lisp/re-builder.el (reb-enter-subexp-mode):
* lisp/emacs-lisp/ring.el (ring-previous, ring-next):
* lisp/emacs-lisp/rx.el (rx-check, rx-anything)
(rx-check-any-string, rx-check-any, rx-check-not, rx-=)
(rx-repeat, rx-check-backref, rx-syntax, rx-check-category)
(rx-form):
* lisp/emacs-lisp/smie.el (smie-config-save):
* lisp/emacs-lisp/subr-x.el (internal--check-binding):
* lisp/emacs-lisp/tabulated-list.el (tabulated-list-put-tag):
* lisp/emacs-lisp/testcover.el (testcover-1value):
* lisp/emacs-lisp/timer.el (timer-event-handler):
* lisp/emulation/viper-cmd.el (viper-toggle-parse-sexp-ignore-comments)
(viper-toggle-search-style, viper-kill-buffer)
(viper-brac-function):
* lisp/emulation/viper-macs.el (viper-record-kbd-macro):
* lisp/env.el (setenv):
* lisp/erc/erc-button.el (erc-nick-popup):
* lisp/erc/erc.el (erc-cmd-LOAD, erc-handle-login, english):
* lisp/eshell/em-dirs.el (eshell/cd):
* lisp/eshell/em-glob.el (eshell-glob-regexp)
(eshell-glob-entries):
* lisp/eshell/em-pred.el (eshell-parse-modifiers):
* lisp/eshell/esh-opt.el (eshell-show-usage):
* lisp/facemenu.el (facemenu-add-new-face)
(facemenu-add-new-color):
* lisp/faces.el (read-face-name, read-face-font, describe-face)
(x-resolve-font-name):
* lisp/files-x.el (modify-file-local-variable):
* lisp/files.el (locate-user-emacs-file, find-alternate-file)
(set-auto-mode, hack-one-local-variable--obsolete)
(dir-locals-set-directory-class, write-file, basic-save-buffer)
(delete-directory, copy-directory, recover-session)
(recover-session-finish, insert-directory)
(file-modes-char-to-who, file-modes-symbolic-to-number)
(move-file-to-trash):
* lisp/filesets.el (filesets-add-buffer, filesets-remove-buffer):
* lisp/find-cmd.el (find-generic, find-to-string):
* lisp/finder.el (finder-commentary):
* lisp/font-lock.el (font-lock-fontify-buffer):
* lisp/format.el (format-write-file, format-find-file)
(format-insert-file):
* lisp/frame.el (get-device-terminal, select-frame-by-name):
* lisp/fringe.el (fringe--check-style):
* lisp/gnus/nnmairix.el (nnmairix-widget-create-query):
* lisp/help-fns.el (help-fns--key-bindings)
(help-fns--compiler-macro, help-fns--parent-mode)
(help-fns--obsolete, help-fns--interactive-only)
(describe-function-1, describe-variable):
* lisp/help.el (describe-mode)
(describe-minor-mode-from-indicator):
* lisp/image.el (image-type):
* lisp/international/ccl.el (ccl-dump):
* lisp/international/fontset.el (x-must-resolve-font-name):
* lisp/international/mule-cmds.el (prefer-coding-system)
(select-safe-coding-system-interactively)
(select-safe-coding-system, activate-input-method)
(toggle-input-method, describe-current-input-method)
(describe-language-environment):
* lisp/international/mule-conf.el (code-offset):
* lisp/international/mule-diag.el (describe-character-set)
(list-input-methods-1):
* lisp/mail/feedmail.el (feedmail-run-the-queue):
* lisp/mouse.el (minor-mode-menu-from-indicator):
* lisp/mpc.el (mpc-playlist-rename):
* lisp/msb.el (msb--choose-menu):
* lisp/net/ange-ftp.el (ange-ftp-shell-command):
* lisp/net/imap.el (imap-interactive-login):
* lisp/net/mairix.el (mairix-widget-create-query):
* lisp/net/newst-backend.el (newsticker--sentinel-work):
* lisp/net/newst-treeview.el (newsticker--treeview-load):
* lisp/net/rlogin.el (rlogin):
* lisp/obsolete/iswitchb.el (iswitchb-possible-new-buffer):
* lisp/obsolete/otodo-mode.el (todo-more-important-p):
* lisp/obsolete/pgg-gpg.el (pgg-gpg-process-region):
* lisp/obsolete/pgg-pgp.el (pgg-pgp-process-region):
* lisp/obsolete/pgg-pgp5.el (pgg-pgp5-process-region):
* lisp/org/ob-core.el (org-babel-goto-named-src-block)
(org-babel-goto-named-result):
* lisp/org/ob-fortran.el (org-babel-fortran-ensure-main-wrap):
* lisp/org/ob-ref.el (org-babel-ref-resolve):
* lisp/org/org-agenda.el (org-agenda-prepare):
* lisp/org/org-clock.el (org-clock-notify-once-if-expired)
(org-clock-resolve):
* lisp/org/org-ctags.el (org-ctags-ask-rebuild-tags-file-then-find-tag):
* lisp/org/org-feed.el (org-feed-parse-atom-entry):
* lisp/org/org-habit.el (org-habit-parse-todo):
* lisp/org/org-mouse.el (org-mouse-popup-global-menu)
(org-mouse-context-menu):
* lisp/org/org-table.el (org-table-edit-formulas):
* lisp/org/ox.el (org-export-async-start):
* lisp/proced.el (proced-log):
* lisp/progmodes/ada-mode.el (ada-get-indent-case)
(ada-check-matching-start, ada-goto-matching-start):
* lisp/progmodes/ada-prj.el (ada-prj-display-page):
* lisp/progmodes/ada-xref.el (ada-find-executable):
* lisp/progmodes/ebrowse.el (ebrowse-tags-apropos):
* lisp/progmodes/etags.el (etags-tags-apropos-additional):
* lisp/progmodes/flymake.el (flymake-parse-err-lines)
(flymake-start-syntax-check-process):
* lisp/progmodes/python.el (python-shell-get-process-or-error)
(python-define-auxiliary-skeleton):
* lisp/progmodes/sql.el (sql-comint):
* lisp/progmodes/verilog-mode.el (verilog-load-file-at-point):
* lisp/progmodes/vhdl-mode.el (vhdl-widget-directory-validate):
* lisp/recentf.el (recentf-open-files):
* lisp/replace.el (query-replace-read-from)
(occur-after-change-function, occur-1):
* lisp/scroll-bar.el (scroll-bar-columns):
* lisp/server.el (server-get-auth-key):
* lisp/simple.el (execute-extended-command)
(undo-outer-limit-truncate, list-processes--refresh)
(compose-mail, set-variable, choose-completion-string)
(define-alternatives):
* lisp/startup.el (site-run-file, tty-handle-args, command-line)
(command-line-1):
* lisp/subr.el (noreturn, define-error, add-to-list)
(read-char-choice, version-to-list):
* lisp/term/common-win.el (x-handle-xrm-switch)
(x-handle-name-switch, x-handle-args):
* lisp/term/x-win.el (x-handle-parent-id, x-handle-smid):
* lisp/textmodes/reftex-ref.el (reftex-label):
* lisp/textmodes/reftex-toc.el (reftex-toc-rename-label):
* lisp/textmodes/two-column.el (2C-split):
* lisp/tutorial.el (tutorial--describe-nonstandard-key)
(tutorial--find-changed-keys):
* lisp/type-break.el (type-break-noninteractive-query):
* lisp/wdired.el (wdired-do-renames, wdired-do-symlink-changes)
(wdired-do-perm-changes):
* lisp/whitespace.el (whitespace-report-region):
Prefer grave quoting in source-code strings used to generate help
and diagnostics.
* lisp/faces.el (face-documentation):
No need to convert quotes, since the result is a docstring.
* lisp/info.el (Info-virtual-index-find-node)
(Info-virtual-index, info-apropos):
Simplify by generating only curved quotes, since info files are
typically that ways nowadays anyway.
* lisp/international/mule-diag.el (list-input-methods):
Don’t assume text quoting style is curved.
* lisp/org/org-bibtex.el (org-bibtex-fields):
Revert my recent changes, going back to the old quoting style.
2015-09-07 08:41:44 -07:00
|
|
|
"Variable interpolation is introduced whenever the `$' character
|
2007-12-05 07:09:53 +00:00
|
|
|
appears unquoted in any argument (except when that argument is
|
|
|
|
surrounded by single quotes). It may be used to interpolate a
|
|
|
|
variable value, a subcommand, or even the result of a Lisp form."
|
|
|
|
:tag "Variable handling"
|
|
|
|
:group 'eshell)
|
|
|
|
|
2000-06-23 05:24:10 +00:00
|
|
|
;;; User Variables:
|
|
|
|
|
2011-03-04 20:11:05 -08:00
|
|
|
(defcustom eshell-var-load-hook nil
|
Cosmetic doc fixes for eshell.
* eshell/em-alias.el, eshell/em-banner.el, eshell/em-basic.el:
* eshell/em-cmpl.el, eshell/em-dirs.el, eshell/em-glob.el:
* eshell/em-hist.el, eshell/em-ls.el, eshell/em-pred.el:
* eshell/em-prompt.el, eshell/em-rebind.el, eshell/em-script.el:
* eshell/em-smart.el, eshell/em-term.el, eshell/em-unix.el:
* eshell/esh-cmd.el, eshell/esh-ext.el, eshell/esh-io.el:
* eshell/esh-mode.el, eshell/esh-proc.el, eshell/esh-test.el:
* eshell/esh-util.el, eshell/esh-var.el:
Remove leading `*' from docs of faces and defcustoms.
2010-09-25 14:51:55 -07:00
|
|
|
"A list of functions to call when loading `eshell-var'."
|
2011-03-04 20:11:05 -08:00
|
|
|
:version "24.1" ; removed eshell-var-initialize
|
2019-03-20 12:51:31 -04:00
|
|
|
:type 'hook)
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(defcustom eshell-prefer-lisp-variables nil
|
Cosmetic doc fixes for eshell.
* eshell/em-alias.el, eshell/em-banner.el, eshell/em-basic.el:
* eshell/em-cmpl.el, eshell/em-dirs.el, eshell/em-glob.el:
* eshell/em-hist.el, eshell/em-ls.el, eshell/em-pred.el:
* eshell/em-prompt.el, eshell/em-rebind.el, eshell/em-script.el:
* eshell/em-smart.el, eshell/em-term.el, eshell/em-unix.el:
* eshell/esh-cmd.el, eshell/esh-ext.el, eshell/esh-io.el:
* eshell/esh-mode.el, eshell/esh-proc.el, eshell/esh-test.el:
* eshell/esh-util.el, eshell/esh-var.el:
Remove leading `*' from docs of faces and defcustoms.
2010-09-25 14:51:55 -07:00
|
|
|
"If non-nil, prefer Lisp variables to environment variables."
|
2019-03-20 12:51:31 -04:00
|
|
|
:type 'boolean)
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(defcustom eshell-complete-export-definition t
|
Cosmetic doc fixes for eshell.
* eshell/em-alias.el, eshell/em-banner.el, eshell/em-basic.el:
* eshell/em-cmpl.el, eshell/em-dirs.el, eshell/em-glob.el:
* eshell/em-hist.el, eshell/em-ls.el, eshell/em-pred.el:
* eshell/em-prompt.el, eshell/em-rebind.el, eshell/em-script.el:
* eshell/em-smart.el, eshell/em-term.el, eshell/em-unix.el:
* eshell/esh-cmd.el, eshell/esh-ext.el, eshell/esh-io.el:
* eshell/esh-mode.el, eshell/esh-proc.el, eshell/esh-test.el:
* eshell/esh-util.el, eshell/esh-var.el:
Remove leading `*' from docs of faces and defcustoms.
2010-09-25 14:51:55 -07:00
|
|
|
"If non-nil, completing names for `export' shows current definition."
|
2019-03-20 12:51:31 -04:00
|
|
|
:type 'boolean)
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2002-05-03 20:43:53 +00:00
|
|
|
(defcustom eshell-modify-global-environment nil
|
Cosmetic doc fixes for eshell.
* eshell/em-alias.el, eshell/em-banner.el, eshell/em-basic.el:
* eshell/em-cmpl.el, eshell/em-dirs.el, eshell/em-glob.el:
* eshell/em-hist.el, eshell/em-ls.el, eshell/em-pred.el:
* eshell/em-prompt.el, eshell/em-rebind.el, eshell/em-script.el:
* eshell/em-smart.el, eshell/em-term.el, eshell/em-unix.el:
* eshell/esh-cmd.el, eshell/esh-ext.el, eshell/esh-io.el:
* eshell/esh-mode.el, eshell/esh-proc.el, eshell/esh-test.el:
* eshell/esh-util.el, eshell/esh-var.el:
Remove leading `*' from docs of faces and defcustoms.
2010-09-25 14:51:55 -07:00
|
|
|
"If non-nil, using `export' changes Emacs's global environment."
|
2019-03-20 12:51:31 -04:00
|
|
|
:type 'boolean)
|
2002-05-03 20:43:53 +00:00
|
|
|
|
2000-06-23 05:24:10 +00:00
|
|
|
(defcustom eshell-variable-name-regexp "[A-Za-z0-9_-]+"
|
Cosmetic doc fixes for eshell.
* eshell/em-alias.el, eshell/em-banner.el, eshell/em-basic.el:
* eshell/em-cmpl.el, eshell/em-dirs.el, eshell/em-glob.el:
* eshell/em-hist.el, eshell/em-ls.el, eshell/em-pred.el:
* eshell/em-prompt.el, eshell/em-rebind.el, eshell/em-script.el:
* eshell/em-smart.el, eshell/em-term.el, eshell/em-unix.el:
* eshell/esh-cmd.el, eshell/esh-ext.el, eshell/esh-io.el:
* eshell/esh-mode.el, eshell/esh-proc.el, eshell/esh-test.el:
* eshell/esh-util.el, eshell/esh-var.el:
Remove leading `*' from docs of faces and defcustoms.
2010-09-25 14:51:55 -07:00
|
|
|
"A regexp identifying what constitutes a variable name reference.
|
Prefer directed to neutral quotes
Prefer directed to neutral quotes in docstings and diagnostics.
In docstrings, escape apostrophes that would otherwise be translated
to curved quotes using the newer, simpler rules.
* admin/unidata/unidata-gen.el (unidata-gen-table):
* lisp/align.el (align-region):
* lisp/allout.el (allout-mode, allout-solicit-alternate-bullet):
* lisp/bookmark.el (bookmark-default-annotation-text):
* lisp/calc/calc-aent.el (math-read-if, math-read-factor):
* lisp/calc/calc-lang.el (math-read-giac-subscr)
(math-read-math-subscr):
* lisp/calc/calc-misc.el (report-calc-bug):
* lisp/calc/calc-prog.el (calc-fix-token-name)
(calc-read-parse-table-part):
* lisp/cedet/ede/pmake.el (ede-proj-makefile-insert-dist-rules):
* lisp/cedet/semantic/complete.el (semantic-displayor-show-request):
* lisp/dabbrev.el (dabbrev-expand):
* lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
* lisp/emacs-lisp/elint.el (elint-get-top-forms):
* lisp/emacs-lisp/lisp-mnt.el (lm-verify):
* lisp/emulation/viper-cmd.el (viper-toggle-search-style):
* lisp/erc/erc-button.el (erc-nick-popup):
* lisp/erc/erc.el (erc-cmd-LOAD, erc-handle-login):
* lisp/eshell/em-dirs.el (eshell/cd):
* lisp/eshell/em-glob.el (eshell-glob-regexp):
* lisp/eshell/em-pred.el (eshell-parse-modifiers):
* lisp/eshell/esh-arg.el (eshell-parse-arguments):
* lisp/eshell/esh-opt.el (eshell-show-usage):
* lisp/files-x.el (modify-file-local-variable):
* lisp/filesets.el (filesets-add-buffer, filesets-remove-buffer)
(filesets-update-pre010505):
* lisp/find-cmd.el (find-generic, find-to-string):
* lisp/gnus/auth-source.el (auth-source-netrc-parse-entries):
* lisp/gnus/gnus-agent.el (gnus-agent-check-overview-buffer)
(gnus-agent-fetch-headers):
* lisp/gnus/gnus-int.el (gnus-start-news-server):
* lisp/gnus/gnus-registry.el:
(gnus-registry--split-fancy-with-parent-internal):
* lisp/gnus/gnus-score.el (gnus-summary-increase-score):
* lisp/gnus/gnus-start.el (gnus-convert-old-newsrc):
* lisp/gnus/gnus-topic.el (gnus-topic-rename):
* lisp/gnus/legacy-gnus-agent.el (gnus-agent-unlist-expire-days):
* lisp/gnus/nnmairix.el (nnmairix-widget-create-query):
* lisp/gnus/spam.el (spam-check-blackholes):
* lisp/mail/feedmail.el (feedmail-run-the-queue):
* lisp/mpc.el (mpc-playlist-rename):
* lisp/net/ange-ftp.el (ange-ftp-shell-command):
* lisp/net/mairix.el (mairix-widget-create-query):
* lisp/net/tramp-cache.el:
* lisp/obsolete/otodo-mode.el (todo-more-important-p):
* lisp/obsolete/pgg-gpg.el (pgg-gpg-process-region):
* lisp/obsolete/pgg-pgp.el (pgg-pgp-process-region):
* lisp/obsolete/pgg-pgp5.el (pgg-pgp5-process-region):
* lisp/org/ob-core.el (org-babel-goto-named-src-block)
(org-babel-goto-named-result):
* lisp/org/ob-fortran.el (org-babel-fortran-ensure-main-wrap):
* lisp/org/ob-ref.el (org-babel-ref-resolve):
* lisp/org/org-agenda.el (org-agenda-prepare):
* lisp/org/org-bibtex.el (org-bibtex-fields):
* lisp/org/org-clock.el (org-clock-notify-once-if-expired)
(org-clock-resolve):
* lisp/org/org-feed.el (org-feed-parse-atom-entry):
* lisp/org/org-habit.el (org-habit-parse-todo):
* lisp/org/org-mouse.el (org-mouse-popup-global-menu)
(org-mouse-context-menu):
* lisp/org/org-table.el (org-table-edit-formulas):
* lisp/org/ox.el (org-export-async-start):
* lisp/play/dunnet.el (dun-score, dun-help, dun-endgame-question)
(dun-rooms, dun-endgame-questions):
* lisp/progmodes/ada-mode.el (ada-goto-matching-start):
* lisp/progmodes/ada-xref.el (ada-find-executable):
* lisp/progmodes/antlr-mode.el (antlr-options-alists):
* lisp/progmodes/flymake.el (flymake-parse-err-lines)
(flymake-start-syntax-check-process):
* lisp/progmodes/python.el (python-define-auxiliary-skeleton):
* lisp/progmodes/sql.el (sql-comint):
* lisp/progmodes/verilog-mode.el (verilog-load-file-at-point):
* lisp/server.el (server-get-auth-key):
* lisp/subr.el (version-to-list):
* lisp/textmodes/reftex-ref.el (reftex-label):
* lisp/textmodes/reftex-toc.el (reftex-toc-rename-label):
* lisp/vc/ediff-diff.el (ediff-same-contents):
* lisp/vc/vc-cvs.el (vc-cvs-mode-line-string):
* test/automated/tramp-tests.el (tramp-test33-asynchronous-requests):
Use directed rather than neutral quotes in diagnostics.
2015-08-24 23:39:33 -07:00
|
|
|
Note that this only applies for `$NAME'. If the syntax `$<NAME>' is
|
2000-06-23 05:24:10 +00:00
|
|
|
used, then NAME can contain any character, including angle brackets,
|
|
|
|
if they are quoted with a backslash."
|
2019-03-20 12:51:31 -04:00
|
|
|
:type 'regexp)
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(defcustom eshell-variable-aliases-list
|
2019-03-20 12:51:31 -04:00
|
|
|
`(;; for eshell.el
|
2022-07-06 21:59:11 -07:00
|
|
|
("COLUMNS" ,(lambda () (window-body-width nil 'remap)) t t)
|
|
|
|
("LINES" ,(lambda () (window-body-height nil 'remap)) t t)
|
2022-07-03 20:05:29 -07:00
|
|
|
("INSIDE_EMACS" eshell-inside-emacs t)
|
2023-08-23 13:29:19 -07:00
|
|
|
("PAGER" (,(lambda () (or comint-pager (getenv "PAGER")))
|
|
|
|
. ,(lambda (_ value)
|
|
|
|
;; When unsetting PAGER, be sure to clear its value
|
|
|
|
;; from `process-environment' too.
|
|
|
|
(unless value (setenv "PAGER"))
|
|
|
|
(setq comint-pager value)))
|
|
|
|
t t)
|
2023-01-10 15:35:18 -08:00
|
|
|
("UID" ,(lambda () (file-user-uid)) nil t)
|
2023-07-07 23:18:33 -07:00
|
|
|
("GID" ,(lambda () (file-group-gid)) nil t)
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2022-09-15 12:24:37 -07:00
|
|
|
;; for esh-ext.el
|
|
|
|
("PATH" (,(lambda () (string-join (eshell-get-path t) (path-separator)))
|
|
|
|
. ,(lambda (_ value)
|
|
|
|
(eshell-set-path value)
|
|
|
|
value))
|
|
|
|
t t)
|
|
|
|
|
|
|
|
;; for esh-cmd.el
|
2022-07-06 21:59:11 -07:00
|
|
|
("_" ,(lambda (indices quoted)
|
2019-03-20 12:51:31 -04:00
|
|
|
(if (not indices)
|
|
|
|
(car (last eshell-last-arguments))
|
|
|
|
(eshell-apply-indices eshell-last-arguments
|
2022-07-06 21:59:11 -07:00
|
|
|
indices quoted))))
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
("?" (eshell-last-command-status . nil))
|
|
|
|
("$" (eshell-last-command-result . nil))
|
2022-07-03 20:05:29 -07:00
|
|
|
|
|
|
|
;; for em-alias.el and em-script.el
|
2000-06-23 05:24:10 +00:00
|
|
|
("0" eshell-command-name)
|
2022-07-06 21:59:11 -07:00
|
|
|
("1" ,(lambda () (nth 0 eshell-command-arguments)) nil t)
|
|
|
|
("2" ,(lambda () (nth 1 eshell-command-arguments)) nil t)
|
|
|
|
("3" ,(lambda () (nth 2 eshell-command-arguments)) nil t)
|
|
|
|
("4" ,(lambda () (nth 3 eshell-command-arguments)) nil t)
|
|
|
|
("5" ,(lambda () (nth 4 eshell-command-arguments)) nil t)
|
|
|
|
("6" ,(lambda () (nth 5 eshell-command-arguments)) nil t)
|
|
|
|
("7" ,(lambda () (nth 6 eshell-command-arguments)) nil t)
|
|
|
|
("8" ,(lambda () (nth 7 eshell-command-arguments)) nil t)
|
|
|
|
("9" ,(lambda () (nth 8 eshell-command-arguments)) nil t)
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
("*" (eshell-command-arguments . nil)))
|
Cosmetic doc fixes for eshell.
* eshell/em-alias.el, eshell/em-banner.el, eshell/em-basic.el:
* eshell/em-cmpl.el, eshell/em-dirs.el, eshell/em-glob.el:
* eshell/em-hist.el, eshell/em-ls.el, eshell/em-pred.el:
* eshell/em-prompt.el, eshell/em-rebind.el, eshell/em-script.el:
* eshell/em-smart.el, eshell/em-term.el, eshell/em-unix.el:
* eshell/esh-cmd.el, eshell/esh-ext.el, eshell/esh-io.el:
* eshell/esh-mode.el, eshell/esh-proc.el, eshell/esh-test.el:
* eshell/esh-util.el, eshell/esh-var.el:
Remove leading `*' from docs of faces and defcustoms.
2010-09-25 14:51:55 -07:00
|
|
|
"This list provides aliasing for variable references.
|
2022-07-06 21:59:11 -07:00
|
|
|
Each member is of the following form:
|
|
|
|
|
|
|
|
(NAME VALUE [COPY-TO-ENVIRONMENT] [SIMPLE-FUNCTION])
|
|
|
|
|
|
|
|
NAME defines the name of the variable, VALUE is a Lisp value used to
|
2020-03-30 21:44:47 +02:00
|
|
|
compute the string value that will be returned when the variable is
|
|
|
|
accessed via the syntax `$NAME'.
|
2000-06-23 05:24:10 +00:00
|
|
|
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
If VALUE is a cons (GET . SET), then variable references to NAME
|
|
|
|
will use GET to get the value, and SET to set it. GET and SET
|
|
|
|
can be one of the forms described below. If SET is nil, the
|
|
|
|
variable is read-only.
|
|
|
|
|
2022-07-06 21:59:11 -07:00
|
|
|
If VALUE is a function, its behavior depends on the value of
|
|
|
|
SIMPLE-FUNCTION. If SIMPLE-FUNCTION is nil, call VALUE with two
|
2022-07-12 17:03:08 +03:00
|
|
|
arguments: the list of the indices that were used in the reference,
|
|
|
|
and either t or nil depending on whether or not the variable was
|
|
|
|
quoted with double quotes. For example, if `NAME' were aliased
|
|
|
|
to a function, a reference of `$NAME[10][20]' would result in that
|
|
|
|
function being called with the arguments `((\"10\") (\"20\"))' and
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
nil. If SIMPLE-FUNCTION is non-nil, call the function with no
|
|
|
|
arguments and then pass its return value to `eshell-apply-indices'.
|
|
|
|
|
|
|
|
When VALUE is a function, it's read-only by default. To make it
|
2022-12-26 10:43:57 +01:00
|
|
|
writable, use the (GET . SET) form described above. If SET is a
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
function, it takes two arguments: a list of indices (currently
|
|
|
|
always nil, but reserved for future enhancement), and the new
|
|
|
|
value to set.
|
2020-04-04 12:04:11 +02:00
|
|
|
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
If VALUE is a string, get/set the value for the variable with
|
|
|
|
that name in the current environment. When getting the value, if
|
|
|
|
no variable with that name exists in the environment, but if a
|
|
|
|
symbol with that same name exists and has a value bound to it,
|
|
|
|
return that symbol's value instead. You can prefer symbol values
|
|
|
|
over environment values by setting the value of
|
|
|
|
`eshell-prefer-lisp-variables' to t.
|
2020-03-30 21:44:47 +02:00
|
|
|
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
If VALUE is a symbol, get/set the value bound to it.
|
2020-03-30 21:44:47 +02:00
|
|
|
|
2022-07-06 21:59:11 -07:00
|
|
|
If VALUE has any other type, signal an error.
|
2020-03-30 21:44:47 +02:00
|
|
|
|
2022-07-06 21:59:11 -07:00
|
|
|
Additionally, if COPY-TO-ENVIRONMENT is non-nil, the alias should be
|
2022-07-12 17:03:08 +03:00
|
|
|
copied (a.k.a. \"exported\") to the environment of created subprocesses."
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
:version "29.1"
|
2000-06-23 05:24:10 +00:00
|
|
|
:type '(repeat (list string sexp
|
|
|
|
(choice (const :tag "Copy to environment" t)
|
2022-07-16 14:03:43 +02:00
|
|
|
(const :tag "Use only in Eshell" nil))
|
|
|
|
(choice (const :tag "Call without argument" t)
|
|
|
|
(const :tag "Call with 2 arguments" nil))))
|
2021-12-24 03:24:44 +01:00
|
|
|
:risky t)
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2021-12-23 19:03:53 +01:00
|
|
|
(defvar-keymap eshell-var-mode-map
|
|
|
|
"C-c M-v" #'eshell-insert-envvar)
|
2019-06-26 13:59:06 -05:00
|
|
|
|
2024-01-25 17:54:13 -08:00
|
|
|
;;; Internal Variables:
|
|
|
|
|
|
|
|
(defvar eshell-in-local-scope-p nil
|
|
|
|
"Non-nil if the current command has a local variable scope.
|
|
|
|
This is set to t in `eshell-local-variable-bindings' (which see).")
|
|
|
|
|
|
|
|
(defvar eshell-local-variable-bindings
|
|
|
|
'((eshell-in-local-scope-p t)
|
|
|
|
(process-environment (eshell-copy-environment))
|
|
|
|
(eshell-variable-aliases-list eshell-variable-aliases-list)
|
|
|
|
(eshell-path-env-list eshell-path-env-list)
|
|
|
|
(comint-pager comint-pager))
|
|
|
|
"A list of `let' bindings for local variable (and subcommand) environments.")
|
|
|
|
|
2000-06-23 05:24:10 +00:00
|
|
|
;;; Functions:
|
|
|
|
|
2019-06-26 13:59:06 -05:00
|
|
|
(define-minor-mode eshell-var-mode
|
|
|
|
"Minor mode for the esh-var module.
|
|
|
|
|
|
|
|
\\{eshell-var-mode-map}"
|
|
|
|
:keymap eshell-var-mode-map)
|
|
|
|
|
2019-04-09 14:57:29 -04:00
|
|
|
(defun eshell-var-initialize () ;Called from `eshell-mode' via intern-soft!
|
2000-06-23 05:24:10 +00:00
|
|
|
"Initialize the variable handle code."
|
|
|
|
;; Break the association with our parent's environment. Otherwise,
|
|
|
|
;; changing a variable will affect all of Emacs.
|
2002-05-03 20:43:53 +00:00
|
|
|
(unless eshell-modify-global-environment
|
2020-12-04 10:55:50 +01:00
|
|
|
(setq-local process-environment (eshell-copy-environment)))
|
2023-08-23 13:29:19 -07:00
|
|
|
(make-local-variable 'comint-pager)
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
(setq-local eshell-subcommand-bindings
|
2024-01-25 17:54:13 -08:00
|
|
|
(append eshell-local-variable-bindings
|
|
|
|
eshell-subcommand-bindings))
|
2024-01-26 10:17:19 -08:00
|
|
|
(setq-local eshell-complex-commands
|
|
|
|
(append '("env") eshell-complex-commands))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2020-12-04 10:55:50 +01:00
|
|
|
(setq-local eshell-special-chars-inside-quoting
|
2000-06-23 05:24:10 +00:00
|
|
|
(append eshell-special-chars-inside-quoting '(?$)))
|
2020-12-04 10:55:50 +01:00
|
|
|
(setq-local eshell-special-chars-outside-quoting
|
2000-06-23 05:24:10 +00:00
|
|
|
(append eshell-special-chars-outside-quoting '(?$)))
|
|
|
|
|
Eshell: Try to untangle the dependencies; move 'provide's to the end
* lisp/eshell/esh-arg.el: Move defsubst and vars before first use.
Don't require `esh-mode but esh-util instead.
* lisp/eshell/esh-cmd.el: Require esh-module and esh-io.
* lisp/eshell/esh-ext.el: Don't require esh-proc nor esh-cmd.
(eshell-external-command): Require esh-proc for
eshell-gather-process-output.
* lisp/eshell/esh-mode.el: Don't require esh-io nor esh-var, but
require esh-arg.
(eshell-directory-name): Move from eshell.el.
* lisp/eshell/esh-module.el: Don't require eshell.
* lisp/eshell/esh-opt.el: Don't require esh-ext at top-level.
(eshell--do-opts, eshell-show-usage): Require it here instead.
* lisp/eshell/esh-proc.el: Don't require esh-cmd, but require esh-io.
(eshell-reset-after-proc, eshell-record-process-object)
(eshell-gather-process-output, eshell-send-eof-to-process):
Require esh-mode and esh-var here.
* lisp/eshell/esh-var.el: Require esh-module, esh-arg, and esh-io.
* lisp/eshell/eshell.el: Require esh-module, esh-proc, esh-io, and esh-cmd.
But don't require esh-mode.
(eshell-directory-name): Move to esh-mode.
(eshell-return-exits-minibuffer): Don't bind 'return' and 'M-return'
since we already bind RET and M-RET.
2019-04-08 14:28:34 -04:00
|
|
|
(add-hook 'eshell-parse-argument-hook #'eshell-interpolate-variable t t)
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(add-hook 'eshell-prepare-command-hook
|
Eshell: Try to untangle the dependencies; move 'provide's to the end
* lisp/eshell/esh-arg.el: Move defsubst and vars before first use.
Don't require `esh-mode but esh-util instead.
* lisp/eshell/esh-cmd.el: Require esh-module and esh-io.
* lisp/eshell/esh-ext.el: Don't require esh-proc nor esh-cmd.
(eshell-external-command): Require esh-proc for
eshell-gather-process-output.
* lisp/eshell/esh-mode.el: Don't require esh-io nor esh-var, but
require esh-arg.
(eshell-directory-name): Move from eshell.el.
* lisp/eshell/esh-module.el: Don't require eshell.
* lisp/eshell/esh-opt.el: Don't require esh-ext at top-level.
(eshell--do-opts, eshell-show-usage): Require it here instead.
* lisp/eshell/esh-proc.el: Don't require esh-cmd, but require esh-io.
(eshell-reset-after-proc, eshell-record-process-object)
(eshell-gather-process-output, eshell-send-eof-to-process):
Require esh-mode and esh-var here.
* lisp/eshell/esh-var.el: Require esh-module, esh-arg, and esh-io.
* lisp/eshell/eshell.el: Require esh-module, esh-proc, esh-io, and esh-cmd.
But don't require esh-mode.
(eshell-directory-name): Move to esh-mode.
(eshell-return-exits-minibuffer): Don't bind 'return' and 'M-return'
since we already bind RET and M-RET.
2019-04-08 14:28:34 -04:00
|
|
|
#'eshell-handle-local-variables nil t)
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(when (eshell-using-module 'eshell-cmpl)
|
|
|
|
(add-hook 'pcomplete-try-first-hook
|
Eshell: Try to untangle the dependencies; move 'provide's to the end
* lisp/eshell/esh-arg.el: Move defsubst and vars before first use.
Don't require `esh-mode but esh-util instead.
* lisp/eshell/esh-cmd.el: Require esh-module and esh-io.
* lisp/eshell/esh-ext.el: Don't require esh-proc nor esh-cmd.
(eshell-external-command): Require esh-proc for
eshell-gather-process-output.
* lisp/eshell/esh-mode.el: Don't require esh-io nor esh-var, but
require esh-arg.
(eshell-directory-name): Move from eshell.el.
* lisp/eshell/esh-module.el: Don't require eshell.
* lisp/eshell/esh-opt.el: Don't require esh-ext at top-level.
(eshell--do-opts, eshell-show-usage): Require it here instead.
* lisp/eshell/esh-proc.el: Don't require esh-cmd, but require esh-io.
(eshell-reset-after-proc, eshell-record-process-object)
(eshell-gather-process-output, eshell-send-eof-to-process):
Require esh-mode and esh-var here.
* lisp/eshell/esh-var.el: Require esh-module, esh-arg, and esh-io.
* lisp/eshell/eshell.el: Require esh-module, esh-proc, esh-io, and esh-cmd.
But don't require esh-mode.
(eshell-directory-name): Move to esh-mode.
(eshell-return-exits-minibuffer): Don't bind 'return' and 'M-return'
since we already bind RET and M-RET.
2019-04-08 14:28:34 -04:00
|
|
|
#'eshell-complete-variable-reference nil t)
|
2000-06-23 05:24:10 +00:00
|
|
|
(add-hook 'pcomplete-try-first-hook
|
Eshell: Try to untangle the dependencies; move 'provide's to the end
* lisp/eshell/esh-arg.el: Move defsubst and vars before first use.
Don't require `esh-mode but esh-util instead.
* lisp/eshell/esh-cmd.el: Require esh-module and esh-io.
* lisp/eshell/esh-ext.el: Don't require esh-proc nor esh-cmd.
(eshell-external-command): Require esh-proc for
eshell-gather-process-output.
* lisp/eshell/esh-mode.el: Don't require esh-io nor esh-var, but
require esh-arg.
(eshell-directory-name): Move from eshell.el.
* lisp/eshell/esh-module.el: Don't require eshell.
* lisp/eshell/esh-opt.el: Don't require esh-ext at top-level.
(eshell--do-opts, eshell-show-usage): Require it here instead.
* lisp/eshell/esh-proc.el: Don't require esh-cmd, but require esh-io.
(eshell-reset-after-proc, eshell-record-process-object)
(eshell-gather-process-output, eshell-send-eof-to-process):
Require esh-mode and esh-var here.
* lisp/eshell/esh-var.el: Require esh-module, esh-arg, and esh-io.
* lisp/eshell/eshell.el: Require esh-module, esh-proc, esh-io, and esh-cmd.
But don't require esh-mode.
(eshell-directory-name): Move to esh-mode.
(eshell-return-exits-minibuffer): Don't bind 'return' and 'M-return'
since we already bind RET and M-RET.
2019-04-08 14:28:34 -04:00
|
|
|
#'eshell-complete-variable-assignment nil t)))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2024-01-25 20:58:34 -08:00
|
|
|
(defun eshell-parse-local-variables (args)
|
|
|
|
"Parse a list of ARGS, looking for variable assignments.
|
|
|
|
Variable assignments are of the form \"VAR=value\". If ARGS
|
|
|
|
begins with any such assignments, throw `eshell-replace-command'
|
|
|
|
with a form that will temporarily set those variables.
|
|
|
|
Otherwise, return nil."
|
2024-01-25 17:54:13 -08:00
|
|
|
;; Handle local variable settings by let-binding the entries in
|
|
|
|
;; `eshell-local-variable-bindings' and calling `eshell-set-variable'
|
|
|
|
;; for each variable before the command is invoked.
|
2000-06-23 05:24:10 +00:00
|
|
|
(let ((setvar "\\`\\([A-Za-z_][A-Za-z0-9_]*\\)=\\(.*\\)\\'")
|
2024-01-25 20:58:34 -08:00
|
|
|
(head (car args))
|
|
|
|
(rest (cdr args)))
|
|
|
|
(when (and (stringp head) (string-match setvar head))
|
2023-09-15 13:40:37 -07:00
|
|
|
(throw 'eshell-replace-command
|
2024-01-25 17:54:13 -08:00
|
|
|
`(let ,eshell-local-variable-bindings
|
|
|
|
,@(let (locals)
|
2024-01-25 20:58:34 -08:00
|
|
|
(while (and (stringp head)
|
|
|
|
(string-match setvar head))
|
2024-01-25 17:54:13 -08:00
|
|
|
(push `(eshell-set-variable
|
2024-01-25 20:58:34 -08:00
|
|
|
,(match-string 1 head)
|
|
|
|
,(match-string 2 head))
|
2024-01-25 17:54:13 -08:00
|
|
|
locals)
|
2024-01-25 20:58:34 -08:00
|
|
|
(setq head (pop rest)))
|
2024-01-25 17:54:13 -08:00
|
|
|
(nreverse locals))
|
2024-01-25 20:58:34 -08:00
|
|
|
(eshell-named-command ,head ',rest))))))
|
|
|
|
|
|
|
|
(defun eshell-handle-local-variables ()
|
|
|
|
"Allow for the syntax `VAR=val <command> <args>'."
|
|
|
|
(eshell-parse-local-variables (cons eshell-last-command-name
|
|
|
|
eshell-last-arguments)))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(defun eshell-interpolate-variable ()
|
|
|
|
"Parse a variable interpolation.
|
|
|
|
This function is explicit for adding to `eshell-parse-argument-hook'."
|
|
|
|
(when (and (eq (char-after) ?$)
|
2022-11-08 22:49:23 -08:00
|
|
|
(/= (1+ (point)) (point-max)))
|
2000-06-23 05:24:10 +00:00
|
|
|
(forward-char)
|
2022-11-08 22:49:23 -08:00
|
|
|
(eshell-parse-variable)))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(defun eshell/define (var-alias definition)
|
2002-10-17 16:52:29 +00:00
|
|
|
"Define a VAR-ALIAS using DEFINITION."
|
2022-09-28 09:34:38 -07:00
|
|
|
;; FIXME: This function doesn't work (it produces variable aliases
|
|
|
|
;; in a form not recognized by other parts of the code), and likely
|
|
|
|
;; hasn't worked since before its introduction into Emacs. It
|
|
|
|
;; should either be removed or fixed up.
|
|
|
|
(declare (obsolete nil "29.1"))
|
2000-06-23 05:24:10 +00:00
|
|
|
(if (not definition)
|
|
|
|
(setq eshell-variable-aliases-list
|
|
|
|
(delq (assoc var-alias eshell-variable-aliases-list)
|
|
|
|
eshell-variable-aliases-list))
|
|
|
|
(let ((def (assoc var-alias eshell-variable-aliases-list))
|
|
|
|
(alias-def
|
|
|
|
(list var-alias
|
|
|
|
(list 'quote (if (= (length definition) 1)
|
|
|
|
(car definition)
|
|
|
|
definition)))))
|
|
|
|
(if def
|
|
|
|
(setq eshell-variable-aliases-list
|
|
|
|
(delq (assoc var-alias eshell-variable-aliases-list)
|
|
|
|
eshell-variable-aliases-list)))
|
|
|
|
(setq eshell-variable-aliases-list
|
|
|
|
(cons alias-def
|
|
|
|
eshell-variable-aliases-list))))
|
|
|
|
nil)
|
|
|
|
|
|
|
|
(defun eshell/export (&rest sets)
|
2005-06-14 11:33:54 +00:00
|
|
|
"This alias allows the `export' command to act as bash users expect."
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
(dolist (set sets)
|
|
|
|
(when (and (stringp set)
|
|
|
|
(string-match "^\\([^=]+\\)=\\(.*\\)" set))
|
|
|
|
(eshell-set-variable (match-string 1 set)
|
|
|
|
(match-string 2 set)))))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2000-09-01 22:48:12 +00:00
|
|
|
(defun pcomplete/eshell-mode/export ()
|
|
|
|
"Completion function for Eshell's `export'."
|
|
|
|
(while (pcomplete-here
|
|
|
|
(if eshell-complete-export-definition
|
|
|
|
process-environment
|
|
|
|
(eshell-envvar-names)))))
|
|
|
|
|
2000-08-29 00:47:45 +00:00
|
|
|
(defun eshell/unset (&rest args)
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
"Unset one or more variables.
|
|
|
|
This is equivalent to calling `eshell/set' for all of ARGS with
|
|
|
|
the values of nil for each."
|
|
|
|
(dolist (arg args)
|
|
|
|
(eshell-set-variable arg nil)))
|
2000-08-29 00:47:45 +00:00
|
|
|
|
2000-09-01 22:48:12 +00:00
|
|
|
(defun pcomplete/eshell-mode/unset ()
|
|
|
|
"Completion function for Eshell's `unset'."
|
|
|
|
(while (pcomplete-here (eshell-envvar-names))))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
(defun eshell/set (&rest args)
|
|
|
|
"Allow command-ish use of `set'."
|
|
|
|
(let (last-value)
|
|
|
|
(while args
|
|
|
|
(setq last-value (eshell-set-variable (car args) (cadr args))
|
|
|
|
args (cddr args)))
|
|
|
|
last-value))
|
|
|
|
|
|
|
|
(defun pcomplete/eshell-mode/set ()
|
|
|
|
"Completion function for Eshell's `set'."
|
|
|
|
(while (pcomplete-here (eshell-envvar-names))))
|
|
|
|
|
2000-06-23 05:24:10 +00:00
|
|
|
(defun eshell/setq (&rest args)
|
|
|
|
"Allow command-ish use of `setq'."
|
|
|
|
(let (last-value)
|
|
|
|
(while args
|
|
|
|
(let ((sym (intern (car args)))
|
|
|
|
(val (cadr args)))
|
|
|
|
(setq last-value (set sym val)
|
|
|
|
args (cddr args))))
|
|
|
|
last-value))
|
|
|
|
|
|
|
|
(defun pcomplete/eshell-mode/setq ()
|
|
|
|
"Completion function for Eshell's `setq'."
|
|
|
|
(while (and (pcomplete-here (all-completions pcomplete-stub
|
2021-02-12 16:08:01 -05:00
|
|
|
obarray #'boundp))
|
2000-06-23 05:24:10 +00:00
|
|
|
(pcomplete-here))))
|
|
|
|
|
|
|
|
(defun eshell/env (&rest args)
|
2011-11-12 23:48:23 -08:00
|
|
|
"Implementation of `env' in Lisp."
|
2000-06-23 05:24:10 +00:00
|
|
|
(eshell-eval-using-options
|
|
|
|
"env" args
|
2024-01-25 20:58:34 -08:00
|
|
|
'(;; FIXME: Support more "env" options, like "--unset".
|
|
|
|
(?h "help" nil nil "show this usage screen")
|
2000-06-23 05:24:10 +00:00
|
|
|
:external "env"
|
2024-01-25 20:58:34 -08:00
|
|
|
:parse-leading-options-only
|
2023-08-15 18:51:20 -07:00
|
|
|
:usage "[NAME=VALUE]... [COMMAND]...")
|
2024-01-25 20:58:34 -08:00
|
|
|
(if args
|
|
|
|
(or (eshell-parse-local-variables args)
|
2024-09-25 11:59:32 -07:00
|
|
|
(throw 'eshell-replace-command
|
|
|
|
`(eshell-named-command ,(car args) ',(cdr args))))
|
2024-06-03 22:01:48 -07:00
|
|
|
(eshell-with-buffered-print
|
|
|
|
(dolist (setting (sort (eshell-environment-variables) 'string-lessp))
|
|
|
|
(eshell-buffered-print setting "\n"))))))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(defun eshell-insert-envvar (envvar-name)
|
|
|
|
"Insert ENVVAR-NAME into the current buffer at point."
|
|
|
|
(interactive
|
|
|
|
(list (read-envvar-name "Name of environment variable: " t)))
|
|
|
|
(insert-and-inherit "$" envvar-name))
|
|
|
|
|
|
|
|
(defun eshell-envvar-names (&optional environment)
|
|
|
|
"Return a list of currently visible environment variable names."
|
2023-02-01 17:48:43 -08:00
|
|
|
(delete-dups
|
|
|
|
(append
|
|
|
|
;; Real environment variables
|
|
|
|
(mapcar (lambda (x)
|
|
|
|
(substring x 0 (string-search "=" x)))
|
|
|
|
(or environment process-environment))
|
|
|
|
;; Eshell variable aliases
|
|
|
|
(mapcar #'car eshell-variable-aliases-list))))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(defun eshell-environment-variables ()
|
|
|
|
"Return a `process-environment', fully updated.
|
|
|
|
This involves setting any variable aliases which affect the
|
|
|
|
environment, as specified in `eshell-variable-aliases-list'."
|
|
|
|
(let ((process-environment (eshell-copy-environment)))
|
Make eshell-for obsolete (replaced by dolist)
* eshell/esh-util.el (eshell-for): Make it obsolete.
* eshell/em-alias.el (eshell/alias, eshell-alias-completions):
* eshell/em-dirs.el (eshell-save-some-last-dir):
* eshell/em-hist.el (eshell-save-some-history, eshell-hist-parse-modifier):
* eshell/em-ls.el (eshell-ls-dir, eshell-ls-files, eshell-ls-entries):
* eshell/em-unix.el (eshell/cat, eshell/du, eshell/su):
* eshell/esh-cmd.el (eshell-invoke-directly, eshell-do-eval, eshell/which):
* eshell/esh-ext.el (eshell-find-interpreter):
* eshell/esh-mode.el (eshell-mode):
* eshell/esh-module.el (eshell-unload-extension-modules):
* eshell/esh-proc.el (eshell-process-interact):
* eshell/esh-test.el (eshell-test):
* eshell/esh-util.el (eshell-flatten-list, eshell-winnow-list):
* eshell/esh-var.el (eshell/env, eshell-environment-variables)
(eshell-variables-list):
* eshell/eshell.el (eshell-unload-all-modules):
Replace eshell-for with dolist.
2011-03-04 19:53:41 -08:00
|
|
|
(dolist (var-alias eshell-variable-aliases-list)
|
2000-06-23 05:24:10 +00:00
|
|
|
(if (nth 2 var-alias)
|
|
|
|
(setenv (car var-alias)
|
|
|
|
(eshell-stringify
|
|
|
|
(or (eshell-get-variable (car var-alias)) "")))))
|
|
|
|
process-environment))
|
|
|
|
|
|
|
|
(defun eshell-parse-variable ()
|
|
|
|
"Parse the next variable reference at point.
|
|
|
|
The variable name could refer to either an environment variable, or a
|
|
|
|
Lisp variable. The priority order depends on the setting of
|
|
|
|
`eshell-prefer-lisp-variables'.
|
|
|
|
|
|
|
|
Its purpose is to call `eshell-parse-variable-ref', and then to
|
|
|
|
process any indices that come after the variable reference."
|
|
|
|
(let* ((get-len (when (eq (char-after) ?#)
|
|
|
|
(forward-char) t))
|
2022-11-08 22:49:23 -08:00
|
|
|
(splice (when (eq (char-after) ?@)
|
|
|
|
(forward-char) t))
|
2000-06-23 05:24:10 +00:00
|
|
|
value indices)
|
2022-02-28 17:38:39 -08:00
|
|
|
(setq value (eshell-parse-variable-ref get-len)
|
2000-06-23 05:24:10 +00:00
|
|
|
indices (and (not (eobp))
|
|
|
|
(eq (char-after) ?\[)
|
|
|
|
(eshell-parse-indices))
|
2023-01-18 19:15:38 -08:00
|
|
|
value `(let ((indices ,(eshell-prepare-indices indices))) ,value))
|
2022-02-28 17:38:39 -08:00
|
|
|
(when get-len
|
|
|
|
(setq value `(length ,value)))
|
|
|
|
(when eshell-current-quoted
|
2022-11-08 22:49:23 -08:00
|
|
|
(if splice
|
|
|
|
(setq value `(eshell-list-to-string ,value)
|
|
|
|
splice nil)
|
|
|
|
(setq value `(eshell-stringify ,value))))
|
|
|
|
(setq value `(eshell-escape-arg ,value))
|
|
|
|
(when splice
|
|
|
|
(setq value `(eshell-splice-args ,value)))
|
2022-02-28 17:38:39 -08:00
|
|
|
value))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2022-02-28 17:38:39 -08:00
|
|
|
(defun eshell-parse-variable-ref (&optional modifier-p)
|
2000-06-23 05:24:10 +00:00
|
|
|
"Eval a variable reference.
|
|
|
|
Returns a Lisp form which, if evaluated, will return the value of the
|
|
|
|
variable.
|
|
|
|
|
2022-02-28 17:38:39 -08:00
|
|
|
If MODIFIER-P is non-nil, the value of the variable will be
|
|
|
|
modified by some function. If MODIFIER-P is nil, the value will be
|
|
|
|
used as-is; this allows optimization of some kinds of variable
|
|
|
|
references.
|
|
|
|
|
|
|
|
Possible variable references are:
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
NAME an environment or Lisp variable value
|
2022-02-27 13:20:51 -08:00
|
|
|
\"LONG-NAME\" disambiguates the length of the name
|
2023-01-18 19:15:38 -08:00
|
|
|
\\='LONG-NAME\\=' as above
|
2000-06-23 05:24:10 +00:00
|
|
|
{COMMAND} result of command is variable's value
|
2022-02-27 13:20:51 -08:00
|
|
|
(LISP-FORM) result of Lisp form is variable's value
|
|
|
|
<COMMAND> write the output of command to a temporary file;
|
|
|
|
result is the file name"
|
Cleanup Eshell to rely less on dynamic scoping.
* lisp/eshell/esh-opt.el (eshell-eval-using-options): Don't bind usage-msg,
last-value, and ext-command here. Bind `args' closer to `body'.
(temp-args, last-value, usage-msg, ext-command, args): Don't defvar.
(eshell--args): Declare new dynamic var.
(eshell-do-opt): Add argument `args'. Bind our own usage-msg,
last-value, and ext-command. Pass `args' to `body'.
(eshell-process-args): Bind eshell--args.
(eshell-set-option): Use eshell--args.
* lisp/eshell/eshell.el (eshell): Use derived-mode-p.
* lisp/eshell/esh-var.el (eshell-parse-variable): Use backquote.
(eshell-parse-variable-ref): Remove unused vars `end' and `err'.
(eshell-glob-function): Declare.
* lisp/eshell/esh-util.el: Require cl-lib.
(eshell-read-hosts-file): Avoid add-to-list.
* lisp/eshell/esh-cmd.el (eshell-parse-lisp-argument): Remove unused var
`err'.
* lisp/eshell/em-unix.el (compilation-scroll-output, locate-history-list):
Declare.
(eshell/diff): Remove unused var `err'.
* lisp/eshell/em-rebind.el (eshell-delete-backward-char): Remove unused arg
`killflag'.
* lisp/eshell/em-pred.el (eshell-parse-modifiers): Remove unused var `err'.
* lisp/eshell/em-ls.el (eshell-ls-highlight-alist): Move defvars before
first use.
* lisp/eshell/em-glob.el (eshell-glob-matches, message-shown):
Move declaration before first use.
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias): Use backquotes.
* autorevert.el (auto-revert-notify-handler): Use `cl-dolist' since we
rely on cl-return.
2013-09-12 01:20:07 -04:00
|
|
|
(cond
|
|
|
|
((eq (char-after) ?{)
|
|
|
|
(let ((end (eshell-find-delimiter ?\{ ?\})))
|
2023-03-20 17:25:24 -07:00
|
|
|
(unless end
|
|
|
|
(throw 'eshell-incomplete "${"))
|
|
|
|
(forward-char)
|
|
|
|
(prog1
|
|
|
|
`(eshell-apply-indices
|
|
|
|
(eshell-convert
|
|
|
|
(eshell-command-to-value
|
|
|
|
(eshell-as-subcommand
|
|
|
|
,(let ((subcmd (or (eshell-unescape-inner-double-quote end)
|
|
|
|
(cons (point) end)))
|
|
|
|
(eshell-current-quoted nil))
|
|
|
|
(eshell-parse-command subcmd))))
|
|
|
|
;; If this is a simple double-quoted form like
|
|
|
|
;; "${COMMAND}" (i.e. no indices after the subcommand and
|
|
|
|
;; no `#' modifier before), ensure we convert to a single
|
|
|
|
;; string. This avoids unnecessary work (e.g. splitting
|
|
|
|
;; the output by lines) when it would just be joined back
|
|
|
|
;; together afterwards.
|
|
|
|
,(when (and (not modifier-p) eshell-current-quoted)
|
|
|
|
'(not indices)))
|
|
|
|
indices ,eshell-current-quoted)
|
|
|
|
(goto-char (1+ end)))))
|
Cleanup Eshell to rely less on dynamic scoping.
* lisp/eshell/esh-opt.el (eshell-eval-using-options): Don't bind usage-msg,
last-value, and ext-command here. Bind `args' closer to `body'.
(temp-args, last-value, usage-msg, ext-command, args): Don't defvar.
(eshell--args): Declare new dynamic var.
(eshell-do-opt): Add argument `args'. Bind our own usage-msg,
last-value, and ext-command. Pass `args' to `body'.
(eshell-process-args): Bind eshell--args.
(eshell-set-option): Use eshell--args.
* lisp/eshell/eshell.el (eshell): Use derived-mode-p.
* lisp/eshell/esh-var.el (eshell-parse-variable): Use backquote.
(eshell-parse-variable-ref): Remove unused vars `end' and `err'.
(eshell-glob-function): Declare.
* lisp/eshell/esh-util.el: Require cl-lib.
(eshell-read-hosts-file): Avoid add-to-list.
* lisp/eshell/esh-cmd.el (eshell-parse-lisp-argument): Remove unused var
`err'.
* lisp/eshell/em-unix.el (compilation-scroll-output, locate-history-list):
Declare.
(eshell/diff): Remove unused var `err'.
* lisp/eshell/em-rebind.el (eshell-delete-backward-char): Remove unused arg
`killflag'.
* lisp/eshell/em-pred.el (eshell-parse-modifiers): Remove unused var `err'.
* lisp/eshell/em-ls.el (eshell-ls-highlight-alist): Move defvars before
first use.
* lisp/eshell/em-glob.el (eshell-glob-matches, message-shown):
Move declaration before first use.
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias): Use backquotes.
* autorevert.el (auto-revert-notify-handler): Use `cl-dolist' since we
rely on cl-return.
2013-09-12 01:20:07 -04:00
|
|
|
((eq (char-after) ?\<)
|
|
|
|
(let ((end (eshell-find-delimiter ?\< ?\>)))
|
2023-03-20 17:25:24 -07:00
|
|
|
(unless end
|
|
|
|
(throw 'eshell-incomplete "$<"))
|
|
|
|
(forward-char)
|
|
|
|
(let* ((temp (make-temp-file temporary-file-directory))
|
|
|
|
(subcmd (or (eshell-unescape-inner-double-quote end)
|
|
|
|
(cons (point) end))))
|
|
|
|
(prog1
|
|
|
|
`(let ((eshell-current-handles
|
|
|
|
(eshell-create-handles ,temp 'overwrite)))
|
|
|
|
(progn
|
|
|
|
(eshell-as-subcommand
|
|
|
|
,(let ((eshell-current-quoted nil))
|
|
|
|
(eshell-parse-command subcmd)))
|
|
|
|
(ignore
|
|
|
|
(nconc eshell-this-command-hook
|
|
|
|
;; Quote this lambda; it will be evaluated by
|
|
|
|
;; `eshell-do-eval', which requires very
|
|
|
|
;; particular forms in order to work
|
|
|
|
;; properly. See bug#54190.
|
|
|
|
(list (function
|
|
|
|
(lambda ()
|
|
|
|
(delete-file ,temp)
|
|
|
|
(when-let ((buffer (get-file-buffer ,temp)))
|
|
|
|
(kill-buffer buffer)))))))
|
|
|
|
(eshell-apply-indices ,temp indices ,eshell-current-quoted)))
|
|
|
|
(goto-char (1+ end))))))
|
Cleanup Eshell to rely less on dynamic scoping.
* lisp/eshell/esh-opt.el (eshell-eval-using-options): Don't bind usage-msg,
last-value, and ext-command here. Bind `args' closer to `body'.
(temp-args, last-value, usage-msg, ext-command, args): Don't defvar.
(eshell--args): Declare new dynamic var.
(eshell-do-opt): Add argument `args'. Bind our own usage-msg,
last-value, and ext-command. Pass `args' to `body'.
(eshell-process-args): Bind eshell--args.
(eshell-set-option): Use eshell--args.
* lisp/eshell/eshell.el (eshell): Use derived-mode-p.
* lisp/eshell/esh-var.el (eshell-parse-variable): Use backquote.
(eshell-parse-variable-ref): Remove unused vars `end' and `err'.
(eshell-glob-function): Declare.
* lisp/eshell/esh-util.el: Require cl-lib.
(eshell-read-hosts-file): Avoid add-to-list.
* lisp/eshell/esh-cmd.el (eshell-parse-lisp-argument): Remove unused var
`err'.
* lisp/eshell/em-unix.el (compilation-scroll-output, locate-history-list):
Declare.
(eshell/diff): Remove unused var `err'.
* lisp/eshell/em-rebind.el (eshell-delete-backward-char): Remove unused arg
`killflag'.
* lisp/eshell/em-pred.el (eshell-parse-modifiers): Remove unused var `err'.
* lisp/eshell/em-ls.el (eshell-ls-highlight-alist): Move defvars before
first use.
* lisp/eshell/em-glob.el (eshell-glob-matches, message-shown):
Move declaration before first use.
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias): Use backquotes.
* autorevert.el (auto-revert-notify-handler): Use `cl-dolist' since we
rely on cl-return.
2013-09-12 01:20:07 -04:00
|
|
|
((eq (char-after) ?\()
|
|
|
|
(condition-case nil
|
2022-03-05 11:45:49 -08:00
|
|
|
`(eshell-apply-indices
|
|
|
|
(eshell-command-to-value
|
|
|
|
(eshell-lisp-command
|
|
|
|
',(read (or (eshell-unescape-inner-double-quote (point-max))
|
|
|
|
(current-buffer)))))
|
2022-02-28 17:38:39 -08:00
|
|
|
indices ,eshell-current-quoted)
|
Cleanup Eshell to rely less on dynamic scoping.
* lisp/eshell/esh-opt.el (eshell-eval-using-options): Don't bind usage-msg,
last-value, and ext-command here. Bind `args' closer to `body'.
(temp-args, last-value, usage-msg, ext-command, args): Don't defvar.
(eshell--args): Declare new dynamic var.
(eshell-do-opt): Add argument `args'. Bind our own usage-msg,
last-value, and ext-command. Pass `args' to `body'.
(eshell-process-args): Bind eshell--args.
(eshell-set-option): Use eshell--args.
* lisp/eshell/eshell.el (eshell): Use derived-mode-p.
* lisp/eshell/esh-var.el (eshell-parse-variable): Use backquote.
(eshell-parse-variable-ref): Remove unused vars `end' and `err'.
(eshell-glob-function): Declare.
* lisp/eshell/esh-util.el: Require cl-lib.
(eshell-read-hosts-file): Avoid add-to-list.
* lisp/eshell/esh-cmd.el (eshell-parse-lisp-argument): Remove unused var
`err'.
* lisp/eshell/em-unix.el (compilation-scroll-output, locate-history-list):
Declare.
(eshell/diff): Remove unused var `err'.
* lisp/eshell/em-rebind.el (eshell-delete-backward-char): Remove unused arg
`killflag'.
* lisp/eshell/em-pred.el (eshell-parse-modifiers): Remove unused var `err'.
* lisp/eshell/em-ls.el (eshell-ls-highlight-alist): Move defvars before
first use.
* lisp/eshell/em-glob.el (eshell-glob-matches, message-shown):
Move declaration before first use.
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias): Use backquotes.
* autorevert.el (auto-revert-notify-handler): Use `cl-dolist' since we
rely on cl-return.
2013-09-12 01:20:07 -04:00
|
|
|
(end-of-file
|
2023-02-01 17:48:37 -08:00
|
|
|
(throw 'eshell-incomplete "$("))))
|
2022-03-03 09:37:25 -08:00
|
|
|
((looking-at (rx-to-string
|
|
|
|
`(or "'" ,(if eshell-current-quoted "\\\"" "\""))))
|
|
|
|
(eshell-with-temp-command
|
|
|
|
(or (eshell-unescape-inner-double-quote (point-max))
|
|
|
|
(cons (point) (point-max)))
|
2023-02-01 17:48:37 -08:00
|
|
|
(let (name)
|
|
|
|
(when-let ((delim
|
|
|
|
(catch 'eshell-incomplete
|
|
|
|
(ignore (setq name (if (eq (char-after) ?\')
|
|
|
|
(eshell-parse-literal-quote)
|
|
|
|
(eshell-parse-double-quote)))))))
|
|
|
|
(throw 'eshell-incomplete (concat "$" delim)))
|
2022-02-27 21:04:30 -08:00
|
|
|
(when name
|
2022-02-28 17:38:39 -08:00
|
|
|
`(eshell-get-variable ,(eval name) indices ,eshell-current-quoted)))))
|
Cleanup Eshell to rely less on dynamic scoping.
* lisp/eshell/esh-opt.el (eshell-eval-using-options): Don't bind usage-msg,
last-value, and ext-command here. Bind `args' closer to `body'.
(temp-args, last-value, usage-msg, ext-command, args): Don't defvar.
(eshell--args): Declare new dynamic var.
(eshell-do-opt): Add argument `args'. Bind our own usage-msg,
last-value, and ext-command. Pass `args' to `body'.
(eshell-process-args): Bind eshell--args.
(eshell-set-option): Use eshell--args.
* lisp/eshell/eshell.el (eshell): Use derived-mode-p.
* lisp/eshell/esh-var.el (eshell-parse-variable): Use backquote.
(eshell-parse-variable-ref): Remove unused vars `end' and `err'.
(eshell-glob-function): Declare.
* lisp/eshell/esh-util.el: Require cl-lib.
(eshell-read-hosts-file): Avoid add-to-list.
* lisp/eshell/esh-cmd.el (eshell-parse-lisp-argument): Remove unused var
`err'.
* lisp/eshell/em-unix.el (compilation-scroll-output, locate-history-list):
Declare.
(eshell/diff): Remove unused var `err'.
* lisp/eshell/em-rebind.el (eshell-delete-backward-char): Remove unused arg
`killflag'.
* lisp/eshell/em-pred.el (eshell-parse-modifiers): Remove unused var `err'.
* lisp/eshell/em-ls.el (eshell-ls-highlight-alist): Move defvars before
first use.
* lisp/eshell/em-glob.el (eshell-glob-matches, message-shown):
Move declaration before first use.
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias): Use backquotes.
* autorevert.el (auto-revert-notify-handler): Use `cl-dolist' since we
rely on cl-return.
2013-09-12 01:20:07 -04:00
|
|
|
((assoc (char-to-string (char-after))
|
|
|
|
eshell-variable-aliases-list)
|
|
|
|
(forward-char)
|
2022-02-28 17:38:39 -08:00
|
|
|
`(eshell-get-variable ,(char-to-string (char-before)) indices
|
|
|
|
,eshell-current-quoted))
|
Cleanup Eshell to rely less on dynamic scoping.
* lisp/eshell/esh-opt.el (eshell-eval-using-options): Don't bind usage-msg,
last-value, and ext-command here. Bind `args' closer to `body'.
(temp-args, last-value, usage-msg, ext-command, args): Don't defvar.
(eshell--args): Declare new dynamic var.
(eshell-do-opt): Add argument `args'. Bind our own usage-msg,
last-value, and ext-command. Pass `args' to `body'.
(eshell-process-args): Bind eshell--args.
(eshell-set-option): Use eshell--args.
* lisp/eshell/eshell.el (eshell): Use derived-mode-p.
* lisp/eshell/esh-var.el (eshell-parse-variable): Use backquote.
(eshell-parse-variable-ref): Remove unused vars `end' and `err'.
(eshell-glob-function): Declare.
* lisp/eshell/esh-util.el: Require cl-lib.
(eshell-read-hosts-file): Avoid add-to-list.
* lisp/eshell/esh-cmd.el (eshell-parse-lisp-argument): Remove unused var
`err'.
* lisp/eshell/em-unix.el (compilation-scroll-output, locate-history-list):
Declare.
(eshell/diff): Remove unused var `err'.
* lisp/eshell/em-rebind.el (eshell-delete-backward-char): Remove unused arg
`killflag'.
* lisp/eshell/em-pred.el (eshell-parse-modifiers): Remove unused var `err'.
* lisp/eshell/em-ls.el (eshell-ls-highlight-alist): Move defvars before
first use.
* lisp/eshell/em-glob.el (eshell-glob-matches, message-shown):
Move declaration before first use.
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias): Use backquotes.
* autorevert.el (auto-revert-notify-handler): Use `cl-dolist' since we
rely on cl-return.
2013-09-12 01:20:07 -04:00
|
|
|
((looking-at eshell-variable-name-regexp)
|
|
|
|
(prog1
|
2022-02-28 17:38:39 -08:00
|
|
|
`(eshell-get-variable ,(match-string 0) indices ,eshell-current-quoted)
|
Cleanup Eshell to rely less on dynamic scoping.
* lisp/eshell/esh-opt.el (eshell-eval-using-options): Don't bind usage-msg,
last-value, and ext-command here. Bind `args' closer to `body'.
(temp-args, last-value, usage-msg, ext-command, args): Don't defvar.
(eshell--args): Declare new dynamic var.
(eshell-do-opt): Add argument `args'. Bind our own usage-msg,
last-value, and ext-command. Pass `args' to `body'.
(eshell-process-args): Bind eshell--args.
(eshell-set-option): Use eshell--args.
* lisp/eshell/eshell.el (eshell): Use derived-mode-p.
* lisp/eshell/esh-var.el (eshell-parse-variable): Use backquote.
(eshell-parse-variable-ref): Remove unused vars `end' and `err'.
(eshell-glob-function): Declare.
* lisp/eshell/esh-util.el: Require cl-lib.
(eshell-read-hosts-file): Avoid add-to-list.
* lisp/eshell/esh-cmd.el (eshell-parse-lisp-argument): Remove unused var
`err'.
* lisp/eshell/em-unix.el (compilation-scroll-output, locate-history-list):
Declare.
(eshell/diff): Remove unused var `err'.
* lisp/eshell/em-rebind.el (eshell-delete-backward-char): Remove unused arg
`killflag'.
* lisp/eshell/em-pred.el (eshell-parse-modifiers): Remove unused var `err'.
* lisp/eshell/em-ls.el (eshell-ls-highlight-alist): Move defvars before
first use.
* lisp/eshell/em-glob.el (eshell-glob-matches, message-shown):
Move declaration before first use.
* lisp/eshell/em-alias.el (eshell-maybe-replace-by-alias): Use backquotes.
* autorevert.el (auto-revert-notify-handler): Use `cl-dolist' since we
rely on cl-return.
2013-09-12 01:20:07 -04:00
|
|
|
(goto-char (match-end 0))))
|
|
|
|
(t
|
|
|
|
(error "Invalid variable reference"))))
|
|
|
|
|
|
|
|
(defvar eshell-glob-function)
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(defun eshell-parse-indices ()
|
2022-03-01 18:36:08 -08:00
|
|
|
"Parse and return a list of index-lists.
|
2023-01-20 13:54:20 -08:00
|
|
|
This produces a series of Lisp forms to be processed by
|
|
|
|
`eshell-prepare-indices' and ultimately evaluated by
|
|
|
|
`eshell-do-eval'.
|
2022-03-01 18:36:08 -08:00
|
|
|
|
|
|
|
For example, \"[0 1][2]\" becomes:
|
2023-01-18 19:15:38 -08:00
|
|
|
((\"0\" \"1\") (\"2\"))."
|
2000-06-23 05:24:10 +00:00
|
|
|
(let (indices)
|
|
|
|
(while (eq (char-after) ?\[)
|
|
|
|
(let ((end (eshell-find-delimiter ?\[ ?\])))
|
|
|
|
(if (not end)
|
2023-02-01 17:48:37 -08:00
|
|
|
(throw 'eshell-incomplete "[")
|
2000-06-23 05:24:10 +00:00
|
|
|
(forward-char)
|
2022-03-03 09:37:25 -08:00
|
|
|
(eshell-with-temp-command (or (eshell-unescape-inner-double-quote end)
|
2022-03-01 18:36:08 -08:00
|
|
|
(cons (point) end))
|
|
|
|
(let (eshell-glob-function (eshell-current-quoted nil))
|
|
|
|
(setq indices (cons (eshell-parse-arguments
|
|
|
|
(point-min) (point-max))
|
|
|
|
indices))))
|
2000-06-23 05:24:10 +00:00
|
|
|
(goto-char (1+ end)))))
|
|
|
|
(nreverse indices)))
|
|
|
|
|
2023-01-20 13:54:20 -08:00
|
|
|
(defun eshell-parse-index (index)
|
|
|
|
"Parse a single INDEX in string form.
|
|
|
|
If INDEX looks like a number, return that number.
|
|
|
|
|
|
|
|
If INDEX looks like \"[BEGIN]..[END]\", where BEGIN and END look
|
|
|
|
like integers, return a cons cell of BEGIN and END as numbers;
|
|
|
|
BEGIN and/or END can be omitted here, in which case their value
|
|
|
|
in the cons is nil.
|
|
|
|
|
|
|
|
Otherwise (including if INDEX is not a string), return
|
|
|
|
the original value of INDEX."
|
|
|
|
(save-match-data
|
|
|
|
(cond
|
|
|
|
((and (stringp index) (get-text-property 0 'number index))
|
|
|
|
(string-to-number index))
|
|
|
|
((and (stringp index)
|
|
|
|
(not (text-property-any 0 (length index) 'escaped t index))
|
|
|
|
(string-match (rx string-start
|
|
|
|
(group-n 1 (? (regexp eshell-integer-regexp)))
|
|
|
|
".."
|
|
|
|
(group-n 2 (? (regexp eshell-integer-regexp)))
|
|
|
|
string-end)
|
|
|
|
index))
|
|
|
|
(let ((begin (match-string 1 index))
|
|
|
|
(end (match-string 2 index)))
|
|
|
|
(cons (unless (string-empty-p begin) (string-to-number begin))
|
|
|
|
(unless (string-empty-p end) (string-to-number end)))))
|
|
|
|
(t
|
|
|
|
index))))
|
|
|
|
|
2022-03-01 18:36:08 -08:00
|
|
|
(defun eshell-eval-indices (indices)
|
|
|
|
"Evaluate INDICES, a list of index-lists generated by `eshell-parse-indices'."
|
2023-01-18 19:15:38 -08:00
|
|
|
(declare (obsolete eshell-prepare-indices "30.1"))
|
2022-03-01 18:36:08 -08:00
|
|
|
(mapcar (lambda (i) (mapcar #'eval i)) indices))
|
|
|
|
|
2023-01-18 19:15:38 -08:00
|
|
|
(defun eshell-prepare-indices (indices)
|
|
|
|
"Prepare INDICES to be evaluated by Eshell.
|
|
|
|
INDICES is a list of index-lists generated by `eshell-parse-indices'."
|
|
|
|
`(list ,@(mapcar (lambda (idx-list) (cons 'list idx-list)) indices)))
|
|
|
|
|
2022-02-28 17:38:39 -08:00
|
|
|
(defun eshell-get-variable (name &optional indices quoted)
|
|
|
|
"Get the value for the variable NAME.
|
|
|
|
INDICES is a list of index-lists (see `eshell-parse-indices').
|
|
|
|
If QUOTED is non-nil, this was invoked inside double-quotes."
|
2022-07-08 18:41:07 -07:00
|
|
|
(if-let ((alias (assoc name eshell-variable-aliases-list)))
|
2022-07-06 21:59:11 -07:00
|
|
|
(let ((target (nth 1 alias)))
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
(when (and (not (functionp target))
|
|
|
|
(consp target))
|
|
|
|
(setq target (car target)))
|
2022-07-08 18:41:07 -07:00
|
|
|
(cond
|
|
|
|
((functionp target)
|
2022-07-06 21:59:11 -07:00
|
|
|
(if (nth 3 alias)
|
|
|
|
(eshell-apply-indices (funcall target) indices quoted)
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
(let ((max-arity (cdr (func-arity target))))
|
|
|
|
(if (or (eq max-arity 'many) (>= max-arity 2))
|
|
|
|
(funcall target indices quoted)
|
|
|
|
(display-warning
|
2023-01-17 20:51:15 -08:00
|
|
|
'(eshell variable-alias)
|
|
|
|
(concat "Function for `eshell-variable-aliases-list' "
|
|
|
|
"entry should accept two arguments: INDICES "
|
|
|
|
"and QUOTED.'"))
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
(funcall target indices)))))
|
2022-07-08 18:41:07 -07:00
|
|
|
((symbolp target)
|
|
|
|
(eshell-apply-indices (symbol-value target) indices quoted))
|
|
|
|
(t
|
|
|
|
(eshell-get-variable target indices quoted))))
|
|
|
|
(unless (stringp name)
|
|
|
|
(error "Unknown variable `%s'" (eshell-stringify name)))
|
|
|
|
(eshell-apply-indices
|
|
|
|
(let ((sym (intern-soft name)))
|
|
|
|
(if (and sym (boundp sym)
|
|
|
|
(or eshell-prefer-lisp-variables
|
|
|
|
(memq sym eshell--local-vars) ; bug#15372
|
|
|
|
(not (getenv name))))
|
|
|
|
(symbol-value sym)
|
|
|
|
(getenv name)))
|
|
|
|
indices quoted)))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
(defun eshell-set-variable (name value)
|
|
|
|
"Set the variable named NAME to VALUE.
|
|
|
|
NAME can be a string (in which case it refers to an environment
|
|
|
|
variable or variable alias) or a symbol (in which case it refers
|
|
|
|
to a Lisp variable)."
|
|
|
|
(if-let ((alias (assoc name eshell-variable-aliases-list)))
|
|
|
|
(let ((target (nth 1 alias)))
|
|
|
|
(cond
|
|
|
|
((functionp target)
|
|
|
|
(setq target nil))
|
|
|
|
((consp target)
|
|
|
|
(setq target (cdr target))))
|
|
|
|
(cond
|
|
|
|
((functionp target)
|
|
|
|
(funcall target nil value))
|
|
|
|
((null target)
|
2024-01-25 17:54:13 -08:00
|
|
|
(unless eshell-in-local-scope-p
|
Allow setting the values of variable aliases in Eshell
This makes commands like "COLUMNS=40 some-command" work as expected.
* lisp/eshell/esh-cmd.el (eshell-subcommand-bindings): Remove
'process-environment' from here...
* lisp/eshell/esh-var.el (eshell-var-initialize): ... and add to here,
along with 'eshell-variable-aliases-list'.
(eshell-inside-emacs): Convert to a 'defvar-local' to make it settable
in a particular Eshell buffer.
(eshell-variable-aliases-list): Make $?, $$, and $* read-only and
update docstring.
(eshell-set-variable): New function...
(eshell-handle-local-variables, eshell/export, eshell/unset): ... use
it.
(eshell/set, pcomplete/eshell-mode/set): New functions.
(eshell-get-variable): Get the variable alias's getter function when
appropriate and use a safer method for checking function arity.
* test/lisp/eshell/esh-var-tests.el (esh-var-test/set/env-var)
(esh-var-test/set/symbol, esh-var-test/unset/env-var)
(esh-var-test/unset/symbol, esh-var-test/setq, esh-var-test/export)
(esh-var-test/local-variables, esh-var-test/alias/function)
(esh-var-test/alias/function-pair, esh-var-test/alias/string)
(esh-var-test/alias/string/prefer-lisp, esh-var-test/alias/symbol)
(esh-var-test/alias/symbol-pair, esh-var-test/alias/export)
(esh-var-test/alias/local-variables): New tests.
* doc/misc/eshell.texi (Built-ins): Add 'set' and update 'unset'
documentation.
(Variables): Expand documentation of how to get/set variables.
2022-09-25 21:47:26 -07:00
|
|
|
(error "Variable `%s' is not settable" (eshell-stringify name)))
|
|
|
|
(push `(,name ,(lambda () value) t t)
|
|
|
|
eshell-variable-aliases-list)
|
|
|
|
value)
|
|
|
|
;; Since getting a variable alias with a string target and
|
|
|
|
;; `eshell-prefer-lisp-variables' non-nil gets the
|
|
|
|
;; corresponding Lisp variable, make sure setting does the
|
|
|
|
;; same.
|
|
|
|
((and eshell-prefer-lisp-variables
|
|
|
|
(stringp target))
|
|
|
|
(eshell-set-variable (intern target) value))
|
|
|
|
(t
|
|
|
|
(eshell-set-variable target value))))
|
|
|
|
(cond
|
|
|
|
((stringp name)
|
|
|
|
(setenv name value))
|
|
|
|
((symbolp name)
|
|
|
|
(set name value))
|
|
|
|
(t
|
|
|
|
(error "Unknown variable `%s'" (eshell-stringify name))))))
|
|
|
|
|
2022-02-28 17:38:39 -08:00
|
|
|
(defun eshell-apply-indices (value indices &optional quoted)
|
2000-06-23 05:24:10 +00:00
|
|
|
"Apply to VALUE all of the given INDICES, returning the sub-result.
|
|
|
|
The format of INDICES is:
|
|
|
|
|
|
|
|
((INT-OR-NAME-OR-OTHER INT-OR-NAME INT-OR-NAME ...)
|
|
|
|
...)
|
|
|
|
|
|
|
|
Each member of INDICES represents a level of nesting. If the first
|
|
|
|
member of a sublist is not an integer or name, and the value it's
|
2022-02-28 17:38:39 -08:00
|
|
|
referencing is a string, that will be used as the regexp with which
|
|
|
|
is to divide the string into sub-parts. The default is whitespace.
|
2000-06-23 05:24:10 +00:00
|
|
|
Otherwise, each INT-OR-NAME refers to an element of the list value.
|
|
|
|
Integers imply a direct index, and names, an associate lookup using
|
|
|
|
`assoc'.
|
|
|
|
|
2022-06-06 19:53:39 -07:00
|
|
|
If QUOTED is non-nil, this was invoked inside double-quotes.
|
|
|
|
This affects the behavior of splitting strings: without quoting,
|
|
|
|
the split values are converted to numbers via
|
|
|
|
`eshell-convert-to-number' if possible; with quoting, they're
|
|
|
|
left as strings.
|
2022-02-28 17:38:39 -08:00
|
|
|
|
2000-06-23 05:24:10 +00:00
|
|
|
For example, to retrieve the second element of a user's record in
|
|
|
|
'/etc/passwd', the variable reference would look like:
|
|
|
|
|
2016-05-07 18:40:10 -07:00
|
|
|
${grep johnw /etc/passwd}[: 2]"
|
2023-01-20 13:54:20 -08:00
|
|
|
(dolist (refs indices value)
|
|
|
|
;; For string values, check if the first index looks like a
|
|
|
|
;; regexp, and if so, use that to split the string.
|
|
|
|
(when (stringp value)
|
|
|
|
(let (separator (first (car refs)))
|
|
|
|
(when (stringp (eshell-parse-index first))
|
|
|
|
(setq separator first
|
|
|
|
refs (cdr refs)))
|
|
|
|
(setq value (split-string value separator))
|
|
|
|
(unless quoted
|
|
|
|
(setq value (mapcar #'eshell-convert-to-number value)))))
|
|
|
|
(cond
|
|
|
|
((< (length refs) 0)
|
|
|
|
(error "Invalid array variable index: %s"
|
|
|
|
(eshell-stringify refs)))
|
|
|
|
((= (length refs) 1)
|
|
|
|
(setq value (eshell-index-value value (car refs))))
|
|
|
|
(t
|
|
|
|
(let (new-value)
|
|
|
|
(dolist (ref refs)
|
|
|
|
(push (eshell-index-value value ref) new-value))
|
|
|
|
(setq value (nreverse new-value)))))))
|
|
|
|
|
|
|
|
(pcase-defmacro eshell-index-range (start end)
|
|
|
|
"A pattern that matches an Eshell index range.
|
|
|
|
EXPVAL should be a cons cell, with each slot containing either an
|
|
|
|
integer or nil. If this matches, bind the values of the sltos to
|
|
|
|
START and END."
|
|
|
|
(list '\` (cons (list '\, `(and (or (pred integerp) (pred null)) ,start))
|
|
|
|
(list '\, `(and (or (pred integerp) (pred null)) ,end)))))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(defun eshell-index-value (value index)
|
|
|
|
"Reference VALUE using the given INDEX."
|
2023-01-20 13:54:20 -08:00
|
|
|
(let ((parsed-index (eshell-parse-index index)))
|
|
|
|
(if (ring-p value)
|
|
|
|
(pcase parsed-index
|
|
|
|
((pred integerp)
|
|
|
|
(ring-ref value parsed-index))
|
|
|
|
((eshell-index-range start end)
|
|
|
|
(let* ((len (ring-length value))
|
|
|
|
(real-start (mod (or start 0) len))
|
|
|
|
(real-end (mod (or end len) len)))
|
|
|
|
(when (and (eq real-end 0)
|
|
|
|
(not (eq end 0)))
|
|
|
|
(setq real-end len))
|
|
|
|
(ring-convert-sequence-to-ring
|
|
|
|
(seq-subseq (ring-elements value) real-start real-end))))
|
|
|
|
(_
|
|
|
|
(error "Invalid index for ring: %s" index)))
|
|
|
|
(pcase parsed-index
|
|
|
|
((pred integerp)
|
|
|
|
(when (< parsed-index 0)
|
|
|
|
(setq parsed-index (+ parsed-index (length value))))
|
|
|
|
(seq-elt value parsed-index))
|
|
|
|
((eshell-index-range start end)
|
|
|
|
(seq-subseq value (or start 0) end))
|
|
|
|
(_
|
|
|
|
;; INDEX is some non-integer value, so treat VALUE as an alist.
|
|
|
|
(cdr (assoc parsed-index value)))))))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
;;;_* Variable name completion
|
|
|
|
|
|
|
|
(defun eshell-complete-variable-reference ()
|
|
|
|
"If there is a variable reference, complete it."
|
2022-12-10 20:52:28 -08:00
|
|
|
(let ((arg (pcomplete-actual-arg)))
|
|
|
|
(when (string-match
|
2022-11-08 22:49:23 -08:00
|
|
|
(rx "$" (? (or "#" "@"))
|
2023-02-01 17:48:43 -08:00
|
|
|
(? (or (group-n 1 (regexp eshell-variable-name-regexp)
|
|
|
|
string-end)
|
|
|
|
(seq (group-n 2 (or "'" "\""))
|
|
|
|
(group-n 1 (+ anychar))))))
|
2022-12-10 20:52:28 -08:00
|
|
|
arg)
|
|
|
|
(setq pcomplete-stub (substring arg (match-beginning 1)))
|
2023-02-01 17:48:43 -08:00
|
|
|
(let ((delimiter (match-string 2 arg)))
|
|
|
|
;; When finished with completion, insert the trailing
|
|
|
|
;; delimiter, if any, and add a trailing slash if the variable
|
|
|
|
;; refers to a directory.
|
|
|
|
(add-function
|
|
|
|
:before-until (var pcomplete-exit-function)
|
|
|
|
(lambda (variable status)
|
|
|
|
(when (eq status 'finished)
|
|
|
|
(when delimiter
|
|
|
|
(if (looking-at (regexp-quote delimiter))
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
(insert delimiter)))
|
|
|
|
(let ((non-essential t)
|
|
|
|
(value (eshell-get-variable variable)))
|
|
|
|
(when (and (stringp value) (file-directory-p value))
|
|
|
|
(insert "/")
|
|
|
|
;; Tell Pcomplete not to insert its own termination
|
|
|
|
;; string.
|
|
|
|
t))))))
|
2000-06-23 05:24:10 +00:00
|
|
|
(throw 'pcomplete-completions (eshell-variables-list)))))
|
|
|
|
|
|
|
|
(defun eshell-variables-list ()
|
|
|
|
"Generate list of applicable variables."
|
2023-02-01 17:48:43 -08:00
|
|
|
(let ((argname pcomplete-stub))
|
2000-06-23 05:24:10 +00:00
|
|
|
(sort
|
2023-02-01 17:48:43 -08:00
|
|
|
(append (eshell-envvar-names)
|
|
|
|
(all-completions argname obarray #'boundp))
|
|
|
|
#'string-lessp)))
|
2000-06-23 05:24:10 +00:00
|
|
|
|
|
|
|
(defun eshell-complete-variable-assignment ()
|
|
|
|
"If there is a variable assignment, allow completion of entries."
|
2023-02-24 21:49:54 -08:00
|
|
|
(catch 'not-assignment
|
|
|
|
;; The current argument can only be a variable assignment if all
|
|
|
|
;; arguments leading up to it are also variable assignments. See
|
|
|
|
;; `eshell-handle-local-variables'.
|
|
|
|
(dotimes (offset (1+ pcomplete-index))
|
|
|
|
(unless (string-match (concat "\\`" eshell-variable-name-regexp "=")
|
|
|
|
(pcomplete-actual-arg 'first offset))
|
|
|
|
(throw 'not-assignment nil)))
|
|
|
|
;; We have a variable assignment. Handle it.
|
|
|
|
(let ((arg (pcomplete-actual-arg))
|
|
|
|
(pos (match-end 0)))
|
|
|
|
(when (string-match "\\(:\\)[^:]*\\'" arg)
|
|
|
|
(setq pos (match-end 1)))
|
2000-06-23 05:24:10 +00:00
|
|
|
(setq pcomplete-stub (substring arg pos))
|
|
|
|
(throw 'pcomplete-completions (pcomplete-entries)))))
|
|
|
|
|
Eshell: Try to untangle the dependencies; move 'provide's to the end
* lisp/eshell/esh-arg.el: Move defsubst and vars before first use.
Don't require `esh-mode but esh-util instead.
* lisp/eshell/esh-cmd.el: Require esh-module and esh-io.
* lisp/eshell/esh-ext.el: Don't require esh-proc nor esh-cmd.
(eshell-external-command): Require esh-proc for
eshell-gather-process-output.
* lisp/eshell/esh-mode.el: Don't require esh-io nor esh-var, but
require esh-arg.
(eshell-directory-name): Move from eshell.el.
* lisp/eshell/esh-module.el: Don't require eshell.
* lisp/eshell/esh-opt.el: Don't require esh-ext at top-level.
(eshell--do-opts, eshell-show-usage): Require it here instead.
* lisp/eshell/esh-proc.el: Don't require esh-cmd, but require esh-io.
(eshell-reset-after-proc, eshell-record-process-object)
(eshell-gather-process-output, eshell-send-eof-to-process):
Require esh-mode and esh-var here.
* lisp/eshell/esh-var.el: Require esh-module, esh-arg, and esh-io.
* lisp/eshell/eshell.el: Require esh-module, esh-proc, esh-io, and esh-cmd.
But don't require esh-mode.
(eshell-directory-name): Move to esh-mode.
(eshell-return-exits-minibuffer): Don't bind 'return' and 'M-return'
since we already bind RET and M-RET.
2019-04-08 14:28:34 -04:00
|
|
|
(provide 'esh-var)
|
2000-06-23 05:24:10 +00:00
|
|
|
;;; esh-var.el ends here
|