diff options
| author | Stefan Kangas | 2020-09-02 02:45:39 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2020-09-21 20:38:56 +0200 |
| commit | fb68645b5a258c98acc11efdc3caae80683cc6b0 (patch) | |
| tree | d301a59e36103264a11aa28f846ee88f7001b22e | |
| parent | 600d3f0669742b398d91c421e335fc6680f6fdc0 (diff) | |
| download | emacs-fb68645b5a258c98acc11efdc3caae80683cc6b0.tar.gz emacs-fb68645b5a258c98acc11efdc3caae80683cc6b0.zip | |
Move several completions from eshell to pcomplete (Bug#10585)
* lisp/eshell/em-unix.el (eshell-complete-hostname)
(pcomplete/ftp, pcomplete/ncftp, pcomplete/ping)
(pcomplete/rlogin, pcomplete/telnet, pcomplete/rsh):
Move from here...
* lisp/pcmpl-unix.el (pcmpl-unix-complete-hostname)
(pcomplete/ftp, pcomplete/ncftp, pcomplete/ping)
(pcomplete/rlogin, pcomplete/telnet, pcomplete/rsh):
...to here. Make old names into aliases.
* lisp/eshell/esh-util.el (eshell-hosts-file)
(eshell-host-names, eshell-host-timestamp)
(eshell-read-hosts-file, eshell-read-hosts)
(eshell-read-host-names): Move from here...
* lisp/pcomplete.el (pcomplete-hosts-file)
(pcomplete--host-name-cache)
(pcomplete--host-name-cache-timestamp)
(pcomplete-read-hosts-file, pcomplete-read-hosts)
(pcomplete-read-host-names): ...to here. Make old names into
aliases.
* lisp/eshell/em-unix.el (eshell-complete-host-reference): Update
caller.
| -rw-r--r-- | lisp/eshell/em-unix.el | 27 | ||||
| -rw-r--r-- | lisp/eshell/esh-util.el | 59 | ||||
| -rw-r--r-- | lisp/pcmpl-unix.el | 23 | ||||
| -rw-r--r-- | lisp/pcomplete.el | 44 |
4 files changed, 94 insertions, 59 deletions
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el index fbd3cfbb6fc..fd4cd6716d2 100644 --- a/lisp/eshell/em-unix.el +++ b/lisp/eshell/em-unix.el | |||
| @@ -787,9 +787,9 @@ external command." | |||
| 787 | 787 | ||
| 788 | ;; completions rules for some common UNIX commands | 788 | ;; completions rules for some common UNIX commands |
| 789 | 789 | ||
| 790 | (defsubst eshell-complete-hostname () | 790 | (autoload 'pcmpl-unix-complete-hostname "pcmpl-unix") |
| 791 | "Complete a command that wants a hostname for an argument." | 791 | (define-obsolete-function-alias 'eshell-complete-hostname |
| 792 | (pcomplete-here (eshell-read-host-names))) | 792 | #'pcmpl-unix-complete-hostname "28.1") |
| 793 | 793 | ||
| 794 | (defun eshell-complete-host-reference () | 794 | (defun eshell-complete-host-reference () |
| 795 | "If there is a host reference, complete it." | 795 | "If there is a host reference, complete it." |
| @@ -798,26 +798,7 @@ external command." | |||
| 798 | (when (setq index (string-match "@[a-z.]*\\'" arg)) | 798 | (when (setq index (string-match "@[a-z.]*\\'" arg)) |
| 799 | (setq pcomplete-stub (substring arg (1+ index)) | 799 | (setq pcomplete-stub (substring arg (1+ index)) |
| 800 | pcomplete-last-completion-raw t) | 800 | pcomplete-last-completion-raw t) |
| 801 | (throw 'pcomplete-completions (eshell-read-host-names))))) | 801 | (throw 'pcomplete-completions (pcomplete-read-host-names))))) |
| 802 | |||
| 803 | (defalias 'pcomplete/ftp 'eshell-complete-hostname) | ||
| 804 | (defalias 'pcomplete/ncftp 'eshell-complete-hostname) | ||
| 805 | (defalias 'pcomplete/ping 'eshell-complete-hostname) | ||
| 806 | (defalias 'pcomplete/rlogin 'eshell-complete-hostname) | ||
| 807 | |||
| 808 | (defun pcomplete/telnet () | ||
| 809 | (require 'pcmpl-unix) | ||
| 810 | (pcomplete-opt "xl(pcmpl-unix-user-names)") | ||
| 811 | (eshell-complete-hostname)) | ||
| 812 | |||
| 813 | (defun pcomplete/rsh () | ||
| 814 | "Complete `rsh', which, after the user and hostname, is like xargs." | ||
| 815 | (require 'pcmpl-unix) | ||
| 816 | (pcomplete-opt "l(pcmpl-unix-user-names)") | ||
| 817 | (eshell-complete-hostname) | ||
| 818 | (pcomplete-here (funcall pcomplete-command-completion-function)) | ||
| 819 | (funcall (or (pcomplete-find-completion-function (pcomplete-arg 1)) | ||
| 820 | pcomplete-default-completion-function))) | ||
| 821 | 802 | ||
| 822 | (defvar block-size) | 803 | (defvar block-size) |
| 823 | (defvar by-bytes) | 804 | (defvar by-bytes) |
diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el index ab030ede05b..0122f9be488 100644 --- a/lisp/eshell/esh-util.el +++ b/lisp/eshell/esh-util.el | |||
| @@ -51,9 +51,15 @@ similarly to external commands, as far as successful result output." | |||
| 51 | :group 'eshell-util) | 51 | :group 'eshell-util) |
| 52 | 52 | ||
| 53 | (defcustom eshell-hosts-file "/etc/hosts" | 53 | (defcustom eshell-hosts-file "/etc/hosts" |
| 54 | "The name of the /etc/hosts file." | 54 | "The name of the /etc/hosts file. |
| 55 | Use `pcomplete-hosts-file' instead; this variable is obsolete and | ||
| 56 | has no effect." | ||
| 55 | :type '(choice (const :tag "No hosts file" nil) file) | 57 | :type '(choice (const :tag "No hosts file" nil) file) |
| 56 | :group 'eshell-util) | 58 | :group 'eshell-util) |
| 59 | ;; Don't make it into an alias, because it doesn't really work with | ||
| 60 | ;; custom and risks creating duplicate entries. Just point users to | ||
| 61 | ;; the other variable, which is less frustrating. | ||
| 62 | (make-obsolete-variable 'eshell-hosts-file nil "28.1") | ||
| 57 | 63 | ||
| 58 | (defcustom eshell-handle-errors t | 64 | (defcustom eshell-handle-errors t |
| 59 | "If non-nil, Eshell will handle errors itself. | 65 | "If non-nil, Eshell will handle errors itself. |
| @@ -127,11 +133,14 @@ function `string-to-number'." | |||
| 127 | (defvar eshell-user-timestamp nil | 133 | (defvar eshell-user-timestamp nil |
| 128 | "A timestamp of when the user file was read.") | 134 | "A timestamp of when the user file was read.") |
| 129 | 135 | ||
| 130 | (defvar eshell-host-names nil | 136 | ;;; Obsolete variables: |
| 131 | "A cache the names of frequently accessed hosts.") | ||
| 132 | 137 | ||
| 133 | (defvar eshell-host-timestamp nil | 138 | (define-obsolete-variable-alias 'eshell-host-names |
| 134 | "A timestamp of when the hosts file was read.") | 139 | 'pcomplete--host-name-cache "28.1") |
| 140 | (define-obsolete-variable-alias 'eshell-host-timestamp | ||
| 141 | 'pcomplete--host-name-cache-timestamp "28.1") | ||
| 142 | (defvar pcomplete--host-name-cache) | ||
| 143 | (defvar pcomplete--host-name-cache-timestamp) | ||
| 135 | 144 | ||
| 136 | ;;; Functions: | 145 | ;;; Functions: |
| 137 | 146 | ||
| @@ -479,37 +488,15 @@ list." | |||
| 479 | 488 | ||
| 480 | (defalias 'eshell-user-name 'user-login-name) | 489 | (defalias 'eshell-user-name 'user-login-name) |
| 481 | 490 | ||
| 482 | (defun eshell-read-hosts-file (filename) | 491 | (autoload 'pcomplete-read-hosts-file "pcomplete") |
| 483 | "Read in the hosts from FILENAME, default `eshell-hosts-file'." | 492 | (autoload 'pcomplete-read-hosts "pcomplete") |
| 484 | (let (hosts) | 493 | (autoload 'pcomplete-read-host-names "pcomplete") |
| 485 | (with-temp-buffer | 494 | (define-obsolete-function-alias 'eshell-read-hosts-file |
| 486 | (insert-file-contents (or filename eshell-hosts-file)) | 495 | #'pcomplete-read-hosts-file "28.1") |
| 487 | (goto-char (point-min)) | 496 | (define-obsolete-function-alias 'eshell-read-hosts |
| 488 | (while (re-search-forward | 497 | #'pcomplete-read-hosts "28.1") |
| 489 | ;; "^ \t\\([^# \t\n]+\\)[ \t]+\\([^ \t\n]+\\)\\([ \t]*\\([^ \t\n]+\\)\\)?" | 498 | (define-obsolete-function-alias 'eshell-read-host-names |
| 490 | "^[ \t]*\\([^# \t\n]+\\)[ \t]+\\([^ \t\n].+\\)" nil t) | 499 | #'pcomplete-read-host-names "28.1") |
| 491 | (push (cons (match-string 1) | ||
| 492 | (split-string (match-string 2))) | ||
| 493 | hosts))) | ||
| 494 | (nreverse hosts))) | ||
| 495 | |||
| 496 | (defun eshell-read-hosts (file result-var timestamp-var) | ||
| 497 | "Read the contents of /etc/hosts for host names." | ||
| 498 | (if (or (not (symbol-value result-var)) | ||
| 499 | (not (symbol-value timestamp-var)) | ||
| 500 | (time-less-p | ||
| 501 | (symbol-value timestamp-var) | ||
| 502 | (file-attribute-modification-time (file-attributes file)))) | ||
| 503 | (progn | ||
| 504 | (set result-var (apply #'nconc (eshell-read-hosts-file file))) | ||
| 505 | (set timestamp-var (current-time)))) | ||
| 506 | (symbol-value result-var)) | ||
| 507 | |||
| 508 | (defun eshell-read-host-names () | ||
| 509 | "Read the contents of /etc/hosts for host names." | ||
| 510 | (if eshell-hosts-file | ||
| 511 | (eshell-read-hosts eshell-hosts-file 'eshell-host-names | ||
| 512 | 'eshell-host-timestamp))) | ||
| 513 | 500 | ||
| 514 | (defsubst eshell-copy-environment () | 501 | (defsubst eshell-copy-environment () |
| 515 | "Return an unrelated copy of `process-environment'." | 502 | "Return an unrelated copy of `process-environment'." |
diff --git a/lisp/pcmpl-unix.el b/lisp/pcmpl-unix.el index 822f6f37e78..74f45b95233 100644 --- a/lisp/pcmpl-unix.el +++ b/lisp/pcmpl-unix.el | |||
| @@ -217,6 +217,29 @@ Includes files as well as host names followed by a colon." | |||
| 217 | (pcmpl-ssh-hosts))))))) | 217 | (pcmpl-ssh-hosts))))))) |
| 218 | (complete-with-action action table string pred)))))) | 218 | (complete-with-action action table string pred)))))) |
| 219 | 219 | ||
| 220 | (defsubst pcmpl-unix-complete-hostname () | ||
| 221 | "Complete a command that wants a hostname for an argument." | ||
| 222 | (pcomplete-here (pcomplete-read-host-names))) | ||
| 223 | |||
| 224 | (defalias 'pcomplete/ftp 'pcmpl-unix-complete-hostname) | ||
| 225 | (defalias 'pcomplete/ncftp 'pcmpl-unix-complete-hostname) | ||
| 226 | (defalias 'pcomplete/ping 'pcmpl-unix-complete-hostname) | ||
| 227 | (defalias 'pcomplete/rlogin 'pcmpl-unix-complete-hostname) | ||
| 228 | |||
| 229 | ;;;###autoload | ||
| 230 | (defun pcomplete/telnet () | ||
| 231 | (pcomplete-opt "xl(pcmpl-unix-user-names)") | ||
| 232 | (pcmpl-unix-complete-hostname)) | ||
| 233 | |||
| 234 | ;;;###autoload | ||
| 235 | (defun pcomplete/rsh () | ||
| 236 | "Complete `rsh', which, after the user and hostname, is like xargs." | ||
| 237 | (pcomplete-opt "l(pcmpl-unix-user-names)") | ||
| 238 | (pcmpl-unix-complete-hostname) | ||
| 239 | (pcomplete-here (funcall pcomplete-command-completion-function)) | ||
| 240 | (funcall (or (pcomplete-find-completion-function (pcomplete-arg 1)) | ||
| 241 | pcomplete-default-completion-function))) | ||
| 242 | |||
| 220 | (provide 'pcmpl-unix) | 243 | (provide 'pcmpl-unix) |
| 221 | 244 | ||
| 222 | ;;; pcmpl-unix.el ends here | 245 | ;;; pcmpl-unix.el ends here |
diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index 32e61e84e0d..014f9628b99 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el | |||
| @@ -325,6 +325,10 @@ already terminated by a character, this variable should be locally | |||
| 325 | modified to be an empty string, or the desired separation string." | 325 | modified to be an empty string, or the desired separation string." |
| 326 | :type 'string) | 326 | :type 'string) |
| 327 | 327 | ||
| 328 | (defcustom pcomplete-hosts-file "/etc/hosts" | ||
| 329 | "The name of the /etc/hosts file." | ||
| 330 | :type '(choice (const :tag "No hosts file" nil) file)) | ||
| 331 | |||
| 328 | ;;; Internal Variables: | 332 | ;;; Internal Variables: |
| 329 | 333 | ||
| 330 | ;; for cycling completion support | 334 | ;; for cycling completion support |
| @@ -1289,6 +1293,46 @@ If specific documentation can't be given, be generic." | |||
| 1289 | (skip-chars-backward "\n") | 1293 | (skip-chars-backward "\n") |
| 1290 | (buffer-substring (point-min) (point)))) | 1294 | (buffer-substring (point-min) (point)))) |
| 1291 | 1295 | ||
| 1296 | ;; hostname completion | ||
| 1297 | |||
| 1298 | (defvar pcomplete--host-name-cache nil | ||
| 1299 | "A cache the names of frequently accessed hosts.") | ||
| 1300 | |||
| 1301 | (defvar pcomplete--host-name-cache-timestamp nil | ||
| 1302 | "A timestamp of when the hosts file was read.") | ||
| 1303 | |||
| 1304 | (defun pcomplete-read-hosts-file (filename) | ||
| 1305 | "Read in the hosts from FILENAME, default `pcomplete-hosts-file'." | ||
| 1306 | (let (hosts) | ||
| 1307 | (with-temp-buffer | ||
| 1308 | (insert-file-contents (or filename pcomplete-hosts-file)) | ||
| 1309 | (goto-char (point-min)) | ||
| 1310 | (while (re-search-forward | ||
| 1311 | ;; "^ \t\\([^# \t\n]+\\)[ \t]+\\([^ \t\n]+\\)\\([ \t]*\\([^ \t\n]+\\)\\)?" | ||
| 1312 | "^[ \t]*\\([^# \t\n]+\\)[ \t]+\\([^ \t\n].+\\)" nil t) | ||
| 1313 | (push (cons (match-string 1) | ||
| 1314 | (split-string (match-string 2))) | ||
| 1315 | hosts))) | ||
| 1316 | (nreverse hosts))) | ||
| 1317 | |||
| 1318 | (defun pcomplete-read-hosts (file result-var timestamp-var) | ||
| 1319 | "Read the contents of /etc/hosts for host names." | ||
| 1320 | (if (or (not (symbol-value result-var)) | ||
| 1321 | (not (symbol-value timestamp-var)) | ||
| 1322 | (time-less-p | ||
| 1323 | (symbol-value timestamp-var) | ||
| 1324 | (file-attribute-modification-time (file-attributes file)))) | ||
| 1325 | (progn | ||
| 1326 | (set result-var (apply #'nconc (pcomplete-read-hosts-file file))) | ||
| 1327 | (set timestamp-var (current-time)))) | ||
| 1328 | (symbol-value result-var)) | ||
| 1329 | |||
| 1330 | (defun pcomplete-read-host-names () | ||
| 1331 | "Read the contents of /etc/hosts for host names." | ||
| 1332 | (if pcomplete-hosts-file | ||
| 1333 | (pcomplete-read-hosts pcomplete-hosts-file 'pcomplete--host-name-cache | ||
| 1334 | 'pcomplete--host-name-cache-timestamp))) | ||
| 1335 | |||
| 1292 | ;; create a set of aliases which allow completion functions to be not | 1336 | ;; create a set of aliases which allow completion functions to be not |
| 1293 | ;; quite so verbose | 1337 | ;; quite so verbose |
| 1294 | 1338 | ||