2013-09-12 16:15:53 -04:00
|
|
|
;;; em-basic.el --- basic shell builtin commands -*- lexical-binding:t -*-
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2019-01-01 00:59:58 +00:00
|
|
|
;; Copyright (C) 1999-2019 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:
|
|
|
|
|
|
|
|
;; There are very few basic Eshell commands -- so-called builtins.
|
|
|
|
;; They are: echo, umask, and version.
|
|
|
|
;;
|
|
|
|
;;;_* `echo'
|
|
|
|
;;
|
|
|
|
;; The `echo' command repeats its arguments to the screen. It is
|
|
|
|
;; optional whether this is done in a Lisp-friendly fashion (so that
|
|
|
|
;; the value of echo is useful to a Lisp command using the result of
|
|
|
|
;; echo as an argument), or whether it should try to act like a normal
|
|
|
|
;; shell echo, and always result in a flat string being returned.
|
|
|
|
|
|
|
|
;; An example of the difference is the following:
|
|
|
|
;;
|
|
|
|
;; echo Hello world
|
|
|
|
;;
|
|
|
|
;; If `eshell-plain-echo-behavior' is non-nil, this will yield the
|
|
|
|
;; string "Hello world". If Lisp behavior is enabled, however, it
|
|
|
|
;; will yield a list whose two elements are the strings "Hello" and
|
|
|
|
;; "world". The way to write an equivalent expression for both would
|
|
|
|
;; be:
|
|
|
|
;;
|
|
|
|
;; echo "Hello world"
|
|
|
|
;;
|
|
|
|
;; This always returns a single string.
|
|
|
|
;;
|
|
|
|
;;;_* `umask'
|
|
|
|
;;
|
|
|
|
;; The umask command changes the default file permissions for newly
|
|
|
|
;; created files. It uses the same syntax as bash.
|
|
|
|
|
|
|
|
;;; 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)
|
2008-05-21 03:50:25 +00:00
|
|
|
(require 'eshell)
|
2000-06-23 05:24:10 +00:00
|
|
|
(require 'esh-opt)
|
|
|
|
|
2008-05-21 03:50:25 +00:00
|
|
|
;;;###autoload
|
Replace eshell-defgroup with plain defgroup
Borrowing a trick from vc-sccs.el, wrap the defgroup in a progn
so that the whole thing ends up in the generated autoload file,
esh-groups.el.
* em-alias.el, em-banner.el, em-basic.el, em-cmpl.el, em-dirs.el:
* em-glob.el, em-hist.el, em-ls.el, em-pred.el, em-prompt.el:
* em-rebind.el, em-script.el, em-smart.el, em-term.el, em-unix.el:
* em-xtra.el: Replace eshell-defgroup with (progn (defgroup.
* eshell.el (eshell-defgroup): Remove alias.
2012-06-27 00:08:06 -07:00
|
|
|
(progn
|
|
|
|
(defgroup eshell-basic nil
|
2007-12-05 07:00:23 +00:00
|
|
|
"The \"basic\" code provides a set of convenience functions which
|
|
|
|
are traditionally considered shell builtins. Since all of the
|
|
|
|
functionality provided by them is accessible through Lisp, they are
|
|
|
|
not really builtins at all, but offer a command-oriented way to do the
|
|
|
|
same thing."
|
|
|
|
:tag "Basic shell commands"
|
Replace eshell-defgroup with plain defgroup
Borrowing a trick from vc-sccs.el, wrap the defgroup in a progn
so that the whole thing ends up in the generated autoload file,
esh-groups.el.
* em-alias.el, em-banner.el, em-basic.el, em-cmpl.el, em-dirs.el:
* em-glob.el, em-hist.el, em-ls.el, em-pred.el, em-prompt.el:
* em-rebind.el, em-script.el, em-smart.el, em-term.el, em-unix.el:
* em-xtra.el: Replace eshell-defgroup with (progn (defgroup.
* eshell.el (eshell-defgroup): Remove alias.
2012-06-27 00:08:06 -07:00
|
|
|
:group 'eshell-module))
|
2007-12-05 07:00:23 +00:00
|
|
|
|
|
|
|
(defcustom eshell-plain-echo-behavior 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, `echo' tries to behave like an ordinary shell echo.
|
2007-12-05 07:00:23 +00:00
|
|
|
This comes at some detriment to Lisp functionality. However, the Lisp
|
|
|
|
equivalent of `echo' can always be achieved by using `identity'."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'eshell-basic)
|
|
|
|
|
2000-06-23 05:24:10 +00:00
|
|
|
;;; Functions:
|
|
|
|
|
|
|
|
(defun eshell-echo (args &optional output-newline)
|
|
|
|
"Implementation code for a Lisp version of `echo'.
|
|
|
|
It returns a formatted value that should be passed to `eshell-print'
|
|
|
|
or `eshell-printn' for display."
|
|
|
|
(if eshell-plain-echo-behavior
|
|
|
|
(concat (apply 'eshell-flatten-and-stringify args) "\n")
|
|
|
|
(let ((value
|
|
|
|
(cond
|
|
|
|
((= (length args) 0) "")
|
|
|
|
((= (length args) 1)
|
|
|
|
(car args))
|
|
|
|
(t
|
|
|
|
(mapcar
|
|
|
|
(function
|
|
|
|
(lambda (arg)
|
|
|
|
(if (stringp arg)
|
|
|
|
(set-text-properties 0 (length arg) nil arg))
|
|
|
|
arg))
|
|
|
|
args)))))
|
|
|
|
(if output-newline
|
|
|
|
(cond
|
|
|
|
((stringp value)
|
|
|
|
(concat value "\n"))
|
|
|
|
((listp value)
|
|
|
|
(append value (list "\n")))
|
|
|
|
(t
|
|
|
|
(concat (eshell-stringify value) "\n")))
|
|
|
|
value))))
|
|
|
|
|
|
|
|
(defun eshell/echo (&rest args)
|
|
|
|
"Implementation of `echo'. See `eshell-plain-echo-behavior'."
|
|
|
|
(eshell-eval-using-options
|
|
|
|
"echo" args
|
|
|
|
'((?n nil nil output-newline "terminate with a newline")
|
|
|
|
(?h "help" nil nil "output this help screen")
|
|
|
|
:preserve-args
|
|
|
|
:usage "[-n] [object]")
|
|
|
|
(eshell-echo args output-newline)))
|
|
|
|
|
|
|
|
(defun eshell/printnl (&rest args)
|
Fix typos in docstrings.
* image-dired.el (image-dired-display-thumbs): Fix typo in docstring.
(image-dired-read-comment): Doc fix.
* json.el (json-object-type, json-array-type, json-key-type, json-false)
(json-null, json-read-number):
* minibuffer.el (completion-in-region-functions):
* calendar/cal-tex.el (cal-tex-daily-end, cal-tex-number-weeks)
(cal-tex-cursor-week):
* emacs-lisp/trace.el (trace-function):
* eshell/em-basic.el (eshell/printnl):
* eshell/em-dirs.el (eshell-last-dir-ring, eshell-parse-drive-letter)
(eshell-read-last-dir-ring, eshell-write-last-dir-ring):
* obsolete/levents.el (allocate-event, event-key, event-object)
(event-point, event-process, event-timestamp, event-to-character)
(event-window, event-x, event-x-pixel, event-y, event-y-pixel):
* textmodes/reftex-vars.el (reftex-index-macros-builtin)
(reftex-section-levels, reftex-auto-recenter-toc, reftex-toc-mode-hook)
(reftex-cite-punctuation, reftex-search-unrecursed-path-first)
(reftex-highlight-selection): Fix typos in docstrings.
2010-03-22 17:50:29 +01:00
|
|
|
"Print out each of the arguments, separated by newlines."
|
New function flatten-tree
Co-authored-by: Basil L. Contovounesios <contovob@tcd.ie>
* doc/lispref/lists.texi: Document `flatten-tree'.
* lisp/progmodes/js.el (js--maybe-join):
* lisp/printing.el (pr-switches):
* lisp/lpr.el (lpr-print-region):
* lisp/gnus/nnimap.el (nnimap-find-wanted-parts):
* lisp/gnus/message.el (message-talkative-question):
* lisp/gnus/gnus-sum.el (gnus-remove-thread)
(gnus-thread-highest-number, gnus-thread-latest-date):
* lisp/eshell/esh-util.el (eshell-flatten-and-stringify):
* lisp/eshell/esh-opt.el (eshell-eval-using-options):
* lisp/eshell/esh-ext.el (eshell-external-command):
* lisp/eshell/em-xtra.el (eshell/expr):
* lisp/eshell/em-unix.el (eshell/rm, eshell-mvcpln-template)
(eshell/cat, eshell/make, eshell-poor-mans-grep, eshell-grep)
(eshell/du, eshell/time, eshell/diff, eshell/locate):
* lisp/eshell/em-tramp.el (eshell/su, eshell/sudo):
* lisp/eshell/em-term.el (eshell-exec-visual):
* lisp/eshell/em-dirs.el (eshell-dirs-substitute-cd, eshell/cd):
* lisp/eshell/em-basic.el (eshell/printnl):
Use new flatten-tree.
* lisp/progmodes/js.el (js--flatten-list):
* lisp/lpr.el (lpr-flatten-list):
* lisp/gnus/message.el (message-flatten-list):
* lisp/eshell/esh-util.el (eshell-flatten-list):
Obsolete in favor of Emacs-wide `flatten-tree'.
* lisp/subr.el (flatten-list): Alias to `flatten-tree' for
discoverability.
* lisp/subr.el (flatten-tree): New defun.
* test/lisp/subr-tests.el (subr-tests-flatten-tree): New test.
2018-12-17 12:15:09 +01:00
|
|
|
(let ((elems (flatten-tree args)))
|
2000-06-23 05:24:10 +00:00
|
|
|
(while elems
|
|
|
|
(eshell-printn (eshell-echo (list (car elems))))
|
|
|
|
(setq elems (cdr elems)))))
|
|
|
|
|
|
|
|
(defun eshell/listify (&rest args)
|
|
|
|
"Return the argument(s) as a single list."
|
|
|
|
(if (> (length args) 1)
|
|
|
|
args
|
|
|
|
(if (listp (car args))
|
|
|
|
(car args)
|
|
|
|
(list (car args)))))
|
|
|
|
|
|
|
|
(defun eshell/umask (&rest args)
|
|
|
|
"Shell-like implementation of `umask'."
|
|
|
|
(eshell-eval-using-options
|
|
|
|
"umask" args
|
|
|
|
'((?S "symbolic" nil symbolic-p "display umask symbolically")
|
|
|
|
(?h "help" nil nil "display this usage message")
|
|
|
|
:usage "[-S] [mode]")
|
|
|
|
(if (or (not args) symbolic-p)
|
|
|
|
(let ((modstr
|
|
|
|
(concat "000"
|
|
|
|
(format "%o"
|
|
|
|
(logand (lognot (default-file-modes))
|
|
|
|
511)))))
|
|
|
|
(setq modstr (substring modstr (- (length modstr) 3)))
|
|
|
|
(when symbolic-p
|
|
|
|
(let ((mode (default-file-modes)))
|
|
|
|
(setq modstr
|
|
|
|
(format
|
|
|
|
"u=%s,g=%s,o=%s"
|
|
|
|
(concat (and (= (logand mode 64) 64) "r")
|
|
|
|
(and (= (logand mode 128) 128) "w")
|
|
|
|
(and (= (logand mode 256) 256) "x"))
|
|
|
|
(concat (and (= (logand mode 8) 8) "r")
|
|
|
|
(and (= (logand mode 16) 16) "w")
|
|
|
|
(and (= (logand mode 32) 32) "x"))
|
|
|
|
(concat (and (= (logand mode 1) 1) "r")
|
|
|
|
(and (= (logand mode 2) 2) "w")
|
|
|
|
(and (= (logand mode 4) 4) "x"))))))
|
|
|
|
(eshell-printn modstr))
|
|
|
|
(setcar args (eshell-convert (car args)))
|
|
|
|
(if (numberp (car args))
|
|
|
|
(set-default-file-modes
|
|
|
|
(- 511 (car (read-from-string
|
|
|
|
(concat "?\\" (number-to-string (car args)))))))
|
|
|
|
(error "setting umask symbolically is not yet implemented"))
|
|
|
|
(eshell-print
|
|
|
|
"Warning: umask changed for all new files created by Emacs.\n"))
|
|
|
|
nil))
|
|
|
|
|
2007-12-05 07:00:23 +00:00
|
|
|
(provide 'em-basic)
|
2000-06-23 05:24:10 +00:00
|
|
|
|
2008-05-21 03:50:25 +00:00
|
|
|
;; Local Variables:
|
|
|
|
;; generated-autoload-file: "esh-groups.el"
|
|
|
|
;; End:
|
|
|
|
|
2000-06-23 05:24:10 +00:00
|
|
|
;;; em-basic.el ends here
|