aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/eshell
diff options
context:
space:
mode:
authorAlex Branham2018-12-17 12:15:09 +0100
committerMichael Albinus2018-12-17 12:15:09 +0100
commit36b05dc84247db1391a423df94e4b9a478e29dc5 (patch)
tree6dff27f40a20402aceec355ffc9551d4e3e3525a /lisp/eshell
parent09a6cc4778d4b90a0bb8da646425d04d8f8a6ec9 (diff)
downloademacs-36b05dc84247db1391a423df94e4b9a478e29dc5.tar.gz
emacs-36b05dc84247db1391a423df94e4b9a478e29dc5.zip
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.
Diffstat (limited to 'lisp/eshell')
-rw-r--r--lisp/eshell/em-basic.el2
-rw-r--r--lisp/eshell/em-dirs.el4
-rw-r--r--lisp/eshell/em-term.el2
-rw-r--r--lisp/eshell/em-tramp.el4
-rw-r--r--lisp/eshell/em-unix.el22
-rw-r--r--lisp/eshell/em-xtra.el2
-rw-r--r--lisp/eshell/esh-ext.el2
-rw-r--r--lisp/eshell/esh-opt.el4
-rw-r--r--lisp/eshell/esh-util.el12
9 files changed, 23 insertions, 31 deletions
diff --git a/lisp/eshell/em-basic.el b/lisp/eshell/em-basic.el
index 5201076f485..4a99d838579 100644
--- a/lisp/eshell/em-basic.el
+++ b/lisp/eshell/em-basic.el
@@ -118,7 +118,7 @@ or `eshell-printn' for display."
118 118
119(defun eshell/printnl (&rest args) 119(defun eshell/printnl (&rest args)
120 "Print out each of the arguments, separated by newlines." 120 "Print out each of the arguments, separated by newlines."
121 (let ((elems (eshell-flatten-list args))) 121 (let ((elems (flatten-tree args)))
122 (while elems 122 (while elems
123 (eshell-printn (eshell-echo (list (car elems)))) 123 (eshell-printn (eshell-echo (list (car elems))))
124 (setq elems (cdr elems))))) 124 (setq elems (cdr elems)))))
diff --git a/lisp/eshell/em-dirs.el b/lisp/eshell/em-dirs.el
index 853382888c9..b47f76fbfb2 100644
--- a/lisp/eshell/em-dirs.el
+++ b/lisp/eshell/em-dirs.el
@@ -259,7 +259,7 @@ Thus, this does not include the current directory.")
259 (if (> (length args) 1) 259 (if (> (length args) 1)
260 (error "%s: command not found" (car args)) 260 (error "%s: command not found" (car args))
261 (throw 'eshell-replace-command 261 (throw 'eshell-replace-command
262 (eshell-parse-command "cd" (eshell-flatten-list args))))) 262 (eshell-parse-command "cd" (flatten-tree args)))))
263 263
264(defun eshell-parse-user-reference () 264(defun eshell-parse-user-reference ()
265 "An argument beginning with ~ is a filename to be expanded." 265 "An argument beginning with ~ is a filename to be expanded."
@@ -353,7 +353,7 @@ in the minibuffer:
353 353
354(defun eshell/cd (&rest args) ; all but first ignored 354(defun eshell/cd (&rest args) ; all but first ignored
355 "Alias to extend the behavior of `cd'." 355 "Alias to extend the behavior of `cd'."
356 (setq args (eshell-flatten-list args)) 356 (setq args (flatten-tree args))
357 (let ((path (car args)) 357 (let ((path (car args))
358 (subpath (car (cdr args))) 358 (subpath (car (cdr args)))
359 (case-fold-search (eshell-under-windows-p)) 359 (case-fold-search (eshell-under-windows-p))
diff --git a/lisp/eshell/em-term.el b/lisp/eshell/em-term.el
index ddde47f73d6..fdf40cae85d 100644
--- a/lisp/eshell/em-term.el
+++ b/lisp/eshell/em-term.el
@@ -175,7 +175,7 @@ allowed."
175 (let* (eshell-interpreter-alist 175 (let* (eshell-interpreter-alist
176 (interp (eshell-find-interpreter (car args) (cdr args))) 176 (interp (eshell-find-interpreter (car args) (cdr args)))
177 (program (car interp)) 177 (program (car interp))
178 (args (eshell-flatten-list 178 (args (flatten-tree
179 (eshell-stringify-list (append (cdr interp) 179 (eshell-stringify-list (append (cdr interp)
180 (cdr args))))) 180 (cdr args)))))
181 (term-buf 181 (term-buf
diff --git a/lisp/eshell/em-tramp.el b/lisp/eshell/em-tramp.el
index 9475f4ed949..f77b84d851b 100644
--- a/lisp/eshell/em-tramp.el
+++ b/lisp/eshell/em-tramp.el
@@ -62,7 +62,7 @@
62 "Alias \"su\" to call TRAMP. 62 "Alias \"su\" to call TRAMP.
63 63
64Uses the system su through TRAMP's su method." 64Uses the system su through TRAMP's su method."
65 (setq args (eshell-stringify-list (eshell-flatten-list args))) 65 (setq args (eshell-stringify-list (flatten-tree args)))
66 (let ((orig-args (copy-tree args))) 66 (let ((orig-args (copy-tree args)))
67 (eshell-eval-using-options 67 (eshell-eval-using-options
68 "su" args 68 "su" args
@@ -100,7 +100,7 @@ Become another USER during a login session.")
100 "Alias \"sudo\" to call Tramp. 100 "Alias \"sudo\" to call Tramp.
101 101
102Uses the system sudo through TRAMP's sudo method." 102Uses the system sudo through TRAMP's sudo method."
103 (setq args (eshell-stringify-list (eshell-flatten-list args))) 103 (setq args (eshell-stringify-list (flatten-tree args)))
104 (let ((orig-args (copy-tree args))) 104 (let ((orig-args (copy-tree args)))
105 (eshell-eval-using-options 105 (eshell-eval-using-options
106 "sudo" args 106 "sudo" args
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el
index 3aecebc2ebf..e46e1c417d4 100644
--- a/lisp/eshell/em-unix.el
+++ b/lisp/eshell/em-unix.el
@@ -231,7 +231,7 @@ Otherwise, Emacs will attempt to use rsh to invoke du on the remote machine."
231This is implemented to call either `delete-file', `kill-buffer', 231This is implemented to call either `delete-file', `kill-buffer',
232`kill-process', or `unintern', depending on the nature of the 232`kill-process', or `unintern', depending on the nature of the
233argument." 233argument."
234 (setq args (eshell-flatten-list args)) 234 (setq args (flatten-tree args))
235 (eshell-eval-using-options 235 (eshell-eval-using-options
236 "rm" args 236 "rm" args
237 '((?h "help" nil nil "show this usage screen") 237 '((?h "help" nil nil "show this usage screen")
@@ -481,7 +481,7 @@ Remove the DIRECTORY(ies), if they are empty.")
481 (error "%s: missing destination file or directory" ,command)) 481 (error "%s: missing destination file or directory" ,command))
482 (if (= len 1) 482 (if (= len 1)
483 (nconc args '("."))) 483 (nconc args '(".")))
484 (setq args (eshell-stringify-list (eshell-flatten-list args))) 484 (setq args (eshell-stringify-list (flatten-tree args)))
485 (if (and ,(not (equal command "ln")) 485 (if (and ,(not (equal command "ln"))
486 (string-match eshell-tar-regexp (car (last args))) 486 (string-match eshell-tar-regexp (car (last args)))
487 (or (> (length args) 2) 487 (or (> (length args) 2)
@@ -606,7 +606,7 @@ with `--symbolic'. When creating hard links, each TARGET must exist.")
606 "Implementation of cat in Lisp. 606 "Implementation of cat in Lisp.
607If in a pipeline, or the file is not a regular file, directory or 607If in a pipeline, or the file is not a regular file, directory or
608symlink, then revert to the system's definition of cat." 608symlink, then revert to the system's definition of cat."
609 (setq args (eshell-stringify-list (eshell-flatten-list args))) 609 (setq args (eshell-stringify-list (flatten-tree args)))
610 (if (or eshell-in-pipeline-p 610 (if (or eshell-in-pipeline-p
611 (catch 'special 611 (catch 'special
612 (dolist (arg args) 612 (dolist (arg args)
@@ -670,7 +670,7 @@ Fallback to standard make when called synchronously."
670 (compile (concat "make " (eshell-flatten-and-stringify args)))) 670 (compile (concat "make " (eshell-flatten-and-stringify args))))
671 (throw 'eshell-replace-command 671 (throw 'eshell-replace-command
672 (eshell-parse-command "*make" (eshell-stringify-list 672 (eshell-parse-command "*make" (eshell-stringify-list
673 (eshell-flatten-list args)))))) 673 (flatten-tree args))))))
674 674
675(put 'eshell/make 'eshell-no-numeric-conversions t) 675(put 'eshell/make 'eshell-no-numeric-conversions t)
676 676
@@ -705,7 +705,7 @@ available..."
705 (erase-buffer) 705 (erase-buffer)
706 (occur-mode) 706 (occur-mode)
707 (let ((files (eshell-stringify-list 707 (let ((files (eshell-stringify-list
708 (eshell-flatten-list (cdr args)))) 708 (flatten-tree (cdr args))))
709 (inhibit-redisplay t) 709 (inhibit-redisplay t)
710 string) 710 string)
711 (when (car args) 711 (when (car args)
@@ -750,11 +750,11 @@ external command."
750 (throw 'eshell-replace-command 750 (throw 'eshell-replace-command
751 (eshell-parse-command (concat "*" command) 751 (eshell-parse-command (concat "*" command)
752 (eshell-stringify-list 752 (eshell-stringify-list
753 (eshell-flatten-list args)))) 753 (flatten-tree args))))
754 (let* ((args (mapconcat 'identity 754 (let* ((args (mapconcat 'identity
755 (mapcar 'shell-quote-argument 755 (mapcar 'shell-quote-argument
756 (eshell-stringify-list 756 (eshell-stringify-list
757 (eshell-flatten-list args))) 757 (flatten-tree args)))
758 " ")) 758 " "))
759 (cmd (progn 759 (cmd (progn
760 (set-text-properties 0 (length args) 760 (set-text-properties 0 (length args)
@@ -876,7 +876,7 @@ external command."
876(defun eshell/du (&rest args) 876(defun eshell/du (&rest args)
877 "Implementation of \"du\" in Lisp, passing ARGS." 877 "Implementation of \"du\" in Lisp, passing ARGS."
878 (setq args (if args 878 (setq args (if args
879 (eshell-stringify-list (eshell-flatten-list args)) 879 (eshell-stringify-list (flatten-tree args))
880 '("."))) 880 '(".")))
881 (let ((ext-du (eshell-search-path "du"))) 881 (let ((ext-du (eshell-search-path "du")))
882 (if (and ext-du 882 (if (and ext-du
@@ -976,7 +976,7 @@ Show wall-clock time elapsed during execution of COMMAND.")
976 (eshell-parse-command (car time-args) 976 (eshell-parse-command (car time-args)
977;;; https://lists.gnu.org/r/bug-gnu-emacs/2007-08/msg00205.html 977;;; https://lists.gnu.org/r/bug-gnu-emacs/2007-08/msg00205.html
978 (eshell-stringify-list 978 (eshell-stringify-list
979 (eshell-flatten-list (cdr time-args)))))))) 979 (flatten-tree (cdr time-args))))))))
980 980
981(defun eshell/whoami (&rest _args) 981(defun eshell/whoami (&rest _args)
982 "Make \"whoami\" Tramp aware." 982 "Make \"whoami\" Tramp aware."
@@ -1000,7 +1000,7 @@ Show wall-clock time elapsed during execution of COMMAND.")
1000 1000
1001(defun eshell/diff (&rest args) 1001(defun eshell/diff (&rest args)
1002 "Alias \"diff\" to call Emacs `diff' function." 1002 "Alias \"diff\" to call Emacs `diff' function."
1003 (let ((orig-args (eshell-stringify-list (eshell-flatten-list args)))) 1003 (let ((orig-args (eshell-stringify-list (flatten-tree args))))
1004 (if (or eshell-plain-diff-behavior 1004 (if (or eshell-plain-diff-behavior
1005 (not (and (eshell-interactive-output-p) 1005 (not (and (eshell-interactive-output-p)
1006 (not eshell-in-pipeline-p) 1006 (not eshell-in-pipeline-p)
@@ -1056,7 +1056,7 @@ Show wall-clock time elapsed during execution of COMMAND.")
1056 (string-match "^-" (car args)))) 1056 (string-match "^-" (car args))))
1057 (throw 'eshell-replace-command 1057 (throw 'eshell-replace-command
1058 (eshell-parse-command "*locate" (eshell-stringify-list 1058 (eshell-parse-command "*locate" (eshell-stringify-list
1059 (eshell-flatten-list args)))) 1059 (flatten-tree args))))
1060 (save-selected-window 1060 (save-selected-window
1061 (let ((locate-history-list (list (car args)))) 1061 (let ((locate-history-list (list (car args))))
1062 (locate-with-filter (car args) (cadr args)))))) 1062 (locate-with-filter (car args) (cadr args))))))
diff --git a/lisp/eshell/em-xtra.el b/lisp/eshell/em-xtra.el
index cc84d198544..eb9847c60c3 100644
--- a/lisp/eshell/em-xtra.el
+++ b/lisp/eshell/em-xtra.el
@@ -51,7 +51,7 @@ naturally accessible within Emacs."
51 "Implementation of expr, using the calc package." 51 "Implementation of expr, using the calc package."
52 (if (not (fboundp 'calc-eval)) 52 (if (not (fboundp 'calc-eval))
53 (throw 'eshell-replace-command 53 (throw 'eshell-replace-command
54 (eshell-parse-command "*expr" (eshell-flatten-list args))) 54 (eshell-parse-command "*expr" (flatten-tree args)))
55 ;; to fool the byte-compiler... 55 ;; to fool the byte-compiler...
56 (let ((func 'calc-eval)) 56 (let ((func 'calc-eval))
57 (funcall func (eshell-flatten-and-stringify args))))) 57 (funcall func (eshell-flatten-and-stringify args)))))
diff --git a/lisp/eshell/esh-ext.el b/lisp/eshell/esh-ext.el
index 244cc7ff1f3..9e7d8bb608e 100644
--- a/lisp/eshell/esh-ext.el
+++ b/lisp/eshell/esh-ext.el
@@ -222,7 +222,7 @@ causing the user to wonder if anything's really going on..."
222 222
223(defun eshell-external-command (command args) 223(defun eshell-external-command (command args)
224 "Insert output from an external COMMAND, using ARGS." 224 "Insert output from an external COMMAND, using ARGS."
225 (setq args (eshell-stringify-list (eshell-flatten-list args))) 225 (setq args (eshell-stringify-list (flatten-tree args)))
226 (let ((interp (eshell-find-interpreter 226 (let ((interp (eshell-find-interpreter
227 command 227 command
228 args 228 args
diff --git a/lisp/eshell/esh-opt.el b/lisp/eshell/esh-opt.el
index d7a449450f9..69d10b4ccfc 100644
--- a/lisp/eshell/esh-opt.el
+++ b/lisp/eshell/esh-opt.el
@@ -77,7 +77,7 @@ arguments, some do not. The recognized :KEYWORDS are:
77 arguments. 77 arguments.
78 78
79:preserve-args 79:preserve-args
80 If present, do not pass MACRO-ARGS through `eshell-flatten-list' 80 If present, do not pass MACRO-ARGS through `flatten-tree'
81and `eshell-stringify-list'. 81and `eshell-stringify-list'.
82 82
83:parse-leading-options-only 83:parse-leading-options-only
@@ -106,7 +106,7 @@ let-bound variable `args'."
106 ,(if (memq ':preserve-args (cadr options)) 106 ,(if (memq ':preserve-args (cadr options))
107 macro-args 107 macro-args
108 (list 'eshell-stringify-list 108 (list 'eshell-stringify-list
109 (list 'eshell-flatten-list macro-args)))) 109 (list 'flatten-tree macro-args))))
110 (processed-args (eshell--do-opts ,name ,options temp-args)) 110 (processed-args (eshell--do-opts ,name ,options temp-args))
111 ,@(delete-dups 111 ,@(delete-dups
112 (delq nil (mapcar (lambda (opt) 112 (delq nil (mapcar (lambda (opt)
diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el
index 8fe8c461fdb..b55f8733802 100644
--- a/lisp/eshell/esh-util.el
+++ b/lisp/eshell/esh-util.el
@@ -285,15 +285,7 @@ Prepend remote identification of `default-directory', if any."
285 ,@forms) 285 ,@forms)
286 (setq list-iter (cdr list-iter))))) 286 (setq list-iter (cdr list-iter)))))
287 287
288(defun eshell-flatten-list (args) 288(define-obsolete-function-alias 'eshell-flatten-list #'flatten-tree "27.1")
289 "Flatten any lists within ARGS, so that there are no sublists."
290 (let ((new-list (list t)))
291 (dolist (a args)
292 (if (and (listp a)
293 (listp (cdr a)))
294 (nconc new-list (eshell-flatten-list a))
295 (nconc new-list (list a))))
296 (cdr new-list)))
297 289
298(defun eshell-uniquify-list (l) 290(defun eshell-uniquify-list (l)
299 "Remove occurring multiples in L. You probably want to sort first." 291 "Remove occurring multiples in L. You probably want to sort first."
@@ -330,7 +322,7 @@ Prepend remote identification of `default-directory', if any."
330 322
331(defsubst eshell-flatten-and-stringify (&rest args) 323(defsubst eshell-flatten-and-stringify (&rest args)
332 "Flatten and stringify all of the ARGS into a single string." 324 "Flatten and stringify all of the ARGS into a single string."
333 (mapconcat 'eshell-stringify (eshell-flatten-list args) " ")) 325 (mapconcat 'eshell-stringify (flatten-tree args) " "))
334 326
335(defsubst eshell-directory-files (regexp &optional directory) 327(defsubst eshell-directory-files (regexp &optional directory)
336 "Return a list of files in the given DIRECTORY matching REGEXP." 328 "Return a list of files in the given DIRECTORY matching REGEXP."