aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/comint.el
diff options
context:
space:
mode:
authorStefan Monnier2011-04-20 19:31:06 -0300
committerStefan Monnier2011-04-20 19:31:06 -0300
commitc0a193ea2017fbaa6fb3e64a07125878656da156 (patch)
tree52ecaae3b27b33e9de36b354cbc2d17e2334f411 /lisp/comint.el
parent201133802956936332f1c4ce04eac42dfd1cf1c6 (diff)
downloademacs-c0a193ea2017fbaa6fb3e64a07125878656da156.tar.gz
emacs-c0a193ea2017fbaa6fb3e64a07125878656da156.zip
* lisp/shell.el: Use lexical-binding and std completion UI.
(shell-filter-ctrl-a-ctrl-b): Work as a preoutput filter. (shell-mode): Put shell-filter-ctrl-a-ctrl-b on comint-preoutput-filter-functions rather than on comint-output-filter-functions. (shell-command-completion, shell--command-completion-data) (shell-filename-completion, shell-environment-variable-completion) (shell-c-a-p-replace-by-expanded-directory): New functions. (shell-dynamic-complete-functions, shell-dynamic-complete-command) (shell-dynamic-complete-filename, shell-replace-by-expanded-directory) (shell-dynamic-complete-environment-variable): Use them. (shell-dynamic-complete-as-environment-variable) (shell-dynamic-complete-as-command): Remove. (shell-match-partial-variable): Match past point. * lisp/comint.el: Clean up use of completion-at-point-functions. (comint-completion-at-point): New function. (comint-mode): Use it completion-at-point-functions. (comint-dynamic-complete): Make it obsolete. (comint-replace-by-expanded-history-before-point): Add dry-run arg. (comint-c-a-p-replace-by-expanded-history): New function. (comint-dynamic-complete-functions) (comint-replace-by-expanded-history): Use it. * lisp/minibuffer.el (completion-table-with-terminator): Allow dynamic termination strings. Try harder to avoid second try-completion. (completion-in-region-mode-map): Disable bindings that don't work yet.
Diffstat (limited to 'lisp/comint.el')
-rw-r--r--lisp/comint.el63
1 files changed, 40 insertions, 23 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 735770a8908..8608c0d31e9 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -367,7 +367,7 @@ text matching `comint-prompt-regexp', depending on the value of
367`comint-use-prompt-regexp'.") 367`comint-use-prompt-regexp'.")
368 368
369(defvar comint-dynamic-complete-functions 369(defvar comint-dynamic-complete-functions
370 '(comint-replace-by-expanded-history comint-filename-completion) 370 '(comint-c-a-p-replace-by-expanded-history comint-filename-completion)
371 "List of functions called to perform completion. 371 "List of functions called to perform completion.
372Works like `completion-at-point-functions'. 372Works like `completion-at-point-functions'.
373See also `comint-dynamic-complete'. 373See also `comint-dynamic-complete'.
@@ -493,7 +493,7 @@ executed once when the buffer is created."
493 (define-key map [menu-bar completion complete-file] 493 (define-key map [menu-bar completion complete-file]
494 '("Complete File Name" . comint-dynamic-complete-filename)) 494 '("Complete File Name" . comint-dynamic-complete-filename))
495 (define-key map [menu-bar completion complete] 495 (define-key map [menu-bar completion complete]
496 '("Complete Before Point" . comint-dynamic-complete)) 496 '("Complete at Point" . completion-at-point))
497 ;; Input history: 497 ;; Input history:
498 (define-key map [menu-bar inout] 498 (define-key map [menu-bar inout]
499 (cons "In/Out" (make-sparse-keymap "In/Out"))) 499 (cons "In/Out" (make-sparse-keymap "In/Out")))
@@ -683,6 +683,7 @@ Entry to this mode runs the hooks on `comint-mode-hook'."
683 (setq font-lock-defaults '(nil t)) 683 (setq font-lock-defaults '(nil t))
684 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) 684 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
685 (add-hook 'isearch-mode-hook 'comint-history-isearch-setup nil t) 685 (add-hook 'isearch-mode-hook 'comint-history-isearch-setup nil t)
686 (add-hook 'completion-at-point-functions 'comint-completion-at-point nil t)
686 ;; This behavior is not useful in comint buffers, and is annoying 687 ;; This behavior is not useful in comint buffers, and is annoying
687 (set (make-local-variable 'next-line-add-newlines) nil)) 688 (set (make-local-variable 'next-line-add-newlines) nil))
688 689
@@ -1231,6 +1232,12 @@ See `comint-magic-space' and `comint-replace-by-expanded-history-before-point'.
1231 1232
1232Returns t if successful." 1233Returns t if successful."
1233 (interactive) 1234 (interactive)
1235 (let ((f (comint-c-a-p-replace-by-expanded-history silent start)))
1236 (if f (funcall f))))
1237
1238(defun comint-c-a-p-replace-by-expanded-history (&optional silent start)
1239 "Expand input command history at point.
1240For use on `completion-at-point-functions'."
1234 (if (and comint-input-autoexpand 1241 (if (and comint-input-autoexpand
1235 (if comint-use-prompt-regexp 1242 (if comint-use-prompt-regexp
1236 ;; Use comint-prompt-regexp 1243 ;; Use comint-prompt-regexp
@@ -1240,20 +1247,28 @@ Returns t if successful."
1240 ;; Use input fields. User input that hasn't been entered 1247 ;; Use input fields. User input that hasn't been entered
1241 ;; yet, at the end of the buffer, has a nil `field' property. 1248 ;; yet, at the end of the buffer, has a nil `field' property.
1242 (and (null (get-char-property (point) 'field)) 1249 (and (null (get-char-property (point) 'field))
1243 (string-match "!\\|^\\^" (field-string))))) 1250 (string-match "!\\|^\\^" (field-string))))
1244 ;; Looks like there might be history references in the command. 1251 (catch 'dry-run
1245 (let ((previous-modified-tick (buffer-modified-tick))) 1252 (comint-replace-by-expanded-history-before-point
1246 (comint-replace-by-expanded-history-before-point silent start) 1253 silent start 'dry-run)))
1247 (/= previous-modified-tick (buffer-modified-tick))))) 1254 (lambda ()
1248 1255 ;; Looks like there might be history references in the command.
1249 1256 (let ((previous-modified-tick (buffer-modified-tick)))
1250(defun comint-replace-by-expanded-history-before-point (silent &optional start) 1257 (comint-replace-by-expanded-history-before-point silent start)
1258 (/= previous-modified-tick (buffer-modified-tick))))))
1259
1260
1261(defun comint-replace-by-expanded-history-before-point
1262 (silent &optional start dry-run)
1251 "Expand directory stack reference before point. 1263 "Expand directory stack reference before point.
1252See `comint-replace-by-expanded-history'. Returns t if successful. 1264See `comint-replace-by-expanded-history'. Returns t if successful.
1253 1265
1254If the optional argument START is non-nil, that specifies the 1266If the optional argument START is non-nil, that specifies the
1255start of the text to scan for history references, rather 1267start of the text to scan for history references, rather
1256than the logical beginning of line." 1268than the logical beginning of line.
1269
1270If DRY-RUN is non-nil, throw to DRY-RUN before performing any
1271actual side-effect."
1257 (save-excursion 1272 (save-excursion
1258 (let ((toend (- (line-end-position) (point))) 1273 (let ((toend (- (line-end-position) (point)))
1259 (start (or start (comint-line-beginning-position)))) 1274 (start (or start (comint-line-beginning-position))))
@@ -1274,10 +1289,12 @@ than the logical beginning of line."
1274 (goto-char (1+ (point)))) 1289 (goto-char (1+ (point))))
1275 ((looking-at "![0-9]+\\($\\|[^-]\\)") 1290 ((looking-at "![0-9]+\\($\\|[^-]\\)")
1276 ;; We cannot know the interpreter's idea of input line numbers. 1291 ;; We cannot know the interpreter's idea of input line numbers.
1292 (if dry-run (throw dry-run 'message))
1277 (goto-char (match-end 0)) 1293 (goto-char (match-end 0))
1278 (message "Absolute reference cannot be expanded")) 1294 (message "Absolute reference cannot be expanded"))
1279 ((looking-at "!-\\([0-9]+\\)\\(:?[0-9^$*-]+\\)?") 1295 ((looking-at "!-\\([0-9]+\\)\\(:?[0-9^$*-]+\\)?")
1280 ;; Just a number of args from `number' lines backward. 1296 ;; Just a number of args from `number' lines backward.
1297 (if dry-run (throw dry-run 'history))
1281 (let ((number (1- (string-to-number 1298 (let ((number (1- (string-to-number
1282 (buffer-substring (match-beginning 1) 1299 (buffer-substring (match-beginning 1)
1283 (match-end 1)))))) 1300 (match-end 1))))))
@@ -1293,6 +1310,7 @@ than the logical beginning of line."
1293 (message "Relative reference exceeds input history size")))) 1310 (message "Relative reference exceeds input history size"))))
1294 ((or (looking-at "!!?:?\\([0-9^$*-]+\\)") (looking-at "!!")) 1311 ((or (looking-at "!!?:?\\([0-9^$*-]+\\)") (looking-at "!!"))
1295 ;; Just a number of args from the previous input line. 1312 ;; Just a number of args from the previous input line.
1313 (if dry-run (throw dry-run 'expand))
1296 (replace-match (comint-args (comint-previous-input-string 0) 1314 (replace-match (comint-args (comint-previous-input-string 0)
1297 (match-beginning 1) (match-end 1)) 1315 (match-beginning 1) (match-end 1))
1298 t t) 1316 t t)
@@ -1301,6 +1319,7 @@ than the logical beginning of line."
1301 "!\\??\\({\\(.+\\)}\\|\\(\\sw+\\)\\)\\(:?[0-9^$*-]+\\)?") 1319 "!\\??\\({\\(.+\\)}\\|\\(\\sw+\\)\\)\\(:?[0-9^$*-]+\\)?")
1302 ;; Most recent input starting with or containing (possibly 1320 ;; Most recent input starting with or containing (possibly
1303 ;; protected) string, maybe just a number of args. Phew. 1321 ;; protected) string, maybe just a number of args. Phew.
1322 (if dry-run (throw dry-run 'expand))
1304 (let* ((mb1 (match-beginning 1)) (me1 (match-end 1)) 1323 (let* ((mb1 (match-beginning 1)) (me1 (match-end 1))
1305 (mb2 (match-beginning 2)) (me2 (match-end 2)) 1324 (mb2 (match-beginning 2)) (me2 (match-end 2))
1306 (exp (buffer-substring (or mb2 mb1) (or me2 me1))) 1325 (exp (buffer-substring (or mb2 mb1) (or me2 me1)))
@@ -1322,6 +1341,7 @@ than the logical beginning of line."
1322 (message "History item: %d" (1+ pos))))) 1341 (message "History item: %d" (1+ pos)))))
1323 ((looking-at "\\^\\([^^]+\\)\\^?\\([^^]*\\)\\^?") 1342 ((looking-at "\\^\\([^^]+\\)\\^?\\([^^]*\\)\\^?")
1324 ;; Quick substitution on the previous input line. 1343 ;; Quick substitution on the previous input line.
1344 (if dry-run (throw dry-run 'expand))
1325 (let ((old (buffer-substring (match-beginning 1) (match-end 1))) 1345 (let ((old (buffer-substring (match-beginning 1) (match-end 1)))
1326 (new (buffer-substring (match-beginning 2) (match-end 2))) 1346 (new (buffer-substring (match-beginning 2) (match-end 2)))
1327 (pos nil)) 1347 (pos nil))
@@ -1334,7 +1354,8 @@ than the logical beginning of line."
1334 (replace-match new t t) 1354 (replace-match new t t)
1335 (message "History item: substituted")))) 1355 (message "History item: substituted"))))
1336 (t 1356 (t
1337 (forward-char 1))))))) 1357 (forward-char 1)))))
1358 nil))
1338 1359
1339 1360
1340(defun comint-magic-space (arg) 1361(defun comint-magic-space (arg)
@@ -1740,9 +1761,9 @@ Similarly for Soar, Scheme, etc."
1740 (insert copy) 1761 (insert copy)
1741 copy))) 1762 copy)))
1742 (input (if (not (eq comint-input-autoexpand 'input)) 1763 (input (if (not (eq comint-input-autoexpand 'input))
1743 ;; Just whatever's already there 1764 ;; Just whatever's already there.
1744 intxt 1765 intxt
1745 ;; Expand and leave it visible in buffer 1766 ;; Expand and leave it visible in buffer.
1746 (comint-replace-by-expanded-history t pmark) 1767 (comint-replace-by-expanded-history t pmark)
1747 (buffer-substring pmark (point)))) 1768 (buffer-substring pmark (point))))
1748 (history (if (not (eq comint-input-autoexpand 'history)) 1769 (history (if (not (eq comint-input-autoexpand 'history))
@@ -2990,16 +3011,12 @@ Magic characters are those in `comint-file-name-quote-list'."
2990 (setq i (+ 1 (match-beginning 0))))) 3011 (setq i (+ 1 (match-beginning 0)))))
2991 filename))) 3012 filename)))
2992 3013
3014(defun comint-completion-at-point ()
3015 (run-hook-with-args-until-success 'comint-dynamic-complete-functions))
2993 3016
2994(defun comint-dynamic-complete () 3017(define-obsolete-function-alias
2995 "Dynamically perform completion at point. 3018 'comint-dynamic-complete
2996Calls the functions in `comint-dynamic-complete-functions' to perform 3019 'completion-at-point "24.1")
2997completion until a function returns non-nil, at which point completion is
2998assumed to have occurred."
2999 (interactive)
3000 (let ((completion-at-point-functions comint-dynamic-complete-functions))
3001 (completion-at-point)))
3002
3003 3020
3004(defun comint-dynamic-complete-filename () 3021(defun comint-dynamic-complete-filename ()
3005 "Dynamically complete the filename at point. 3022 "Dynamically complete the filename at point.