Commit 5653b76d authored by Stefan Monnier's avatar Stefan Monnier

* lisp/term.el: Fix minor compilation issues with cl-lib and lexbind

Remove left-over comment from the bulk comint->term query/replace.
(term-command-function): Rename from term-command-hook.
Give it a global default value.
(term-suppress-hard-newline): Mark it as generally obsolete.
(term-mode): Don't manually make hooks buffer-local.
(term--remove-fake-newlines): Fix assert -> cl-assert.
(term-char-mode): Use add-function.
(term-send-input): Use run-hook-with-args.
(term-dynamic-complete): Use run-hook-with-args-until-success.
(term-dynamic-simple-complete): Completion tables can be plain lists.
(serial-read-name): Simplify and fix misuse of `set`.
parent 467e6ccb
Pipeline #852 passed with stage
in 53 minutes and 6 seconds
......@@ -284,17 +284,6 @@
;; merge them into the master source.
;; - Per Bothner (
;; This file defines a general command-interpreter-in-a-buffer package
;; (term mode). The idea is that you can build specific process-in-a-buffer
;; modes on top of term mode -- e.g., lisp, shell, scheme, T, soar, ....
;; This way, all these specific packages share a common base functionality,
;; and a common set of bindings, which makes them easier to use (and
;; saves code, implementation time, etc., etc.).
;; For hints on converting existing process modes (e.g., tex-mode,
;; background, dbx, gdb, kermit, prolog, telnet) to use term-mode
;; instead of shell-mode, see the notes at the end of this file.
;; Brief Command Documentation:
......@@ -406,7 +395,9 @@ This emulates (more or less) the behavior of xterm.")
(defvar term-pager-count nil
"Number of lines before we need to page; if nil, paging is disabled.")
(defvar term-saved-cursor nil)
(defvar term-command-hook)
(define-obsolete-variable-alias 'term-command-hook
'term-command-function "27.1")
(defvar term-command-function #'term-command-hook)
(defvar term-log-buffer nil)
(defvar term-scroll-with-delete nil
"If t, forward scrolling should be implemented by delete to
......@@ -546,8 +537,7 @@ This means text can automatically reflow if the window is resized."
:type 'boolean
:group 'term)
(make-obsolete-variable 'term-suppress-hard-newline nil
;; Where gud-display-frame should put the debugging arrow. This is
;; set by the marker-filter, which scans the debugger's output for
......@@ -582,7 +572,7 @@ These functions get one argument, a string containing the text to send.
This variable is buffer-local.")
(defvar term-input-sender (function term-simple-send)
(defvar term-input-sender #'term-simple-send
"Function to actually send to PROCESS the STRING submitted by user.
Usually this is just `term-simple-send', but if your mode needs to
massage the input string, this is your hook. This is called from
......@@ -1039,8 +1029,6 @@ Entry to this mode runs the hooks on `term-mode-hook'."
(set (make-local-variable 'term-last-input-start) (make-marker))
(set (make-local-variable 'term-last-input-end) (make-marker))
(set (make-local-variable 'term-last-input-match) "")
(set (make-local-variable 'term-command-hook)
(symbol-function 'term-command-hook))
;; These local variables are set to their local values:
(make-local-variable 'term-saved-home-marker)
......@@ -1094,21 +1082,18 @@ Entry to this mode runs the hooks on `term-mode-hook'."
(make-local-variable 'term-pager-old-local-map)
(make-local-variable 'term-old-mode-map)
(make-local-variable 'term-insert-mode)
(make-local-variable 'term-dynamic-complete-functions)
(make-local-variable 'term-completion-fignore)
(make-local-variable 'term-get-old-input)
(make-local-variable 'term-matching-input-from-input-string)
(make-local-variable 'term-input-autoexpand)
(make-local-variable 'term-input-ignoredups)
(make-local-variable 'term-delimiter-argument-list)
(make-local-variable 'term-input-filter-functions)
(make-local-variable 'term-input-filter)
(make-local-variable 'term-input-sender)
(make-local-variable 'term-eol-on-send)
(make-local-variable 'term-scroll-to-bottom-on-output)
(make-local-variable 'term-scroll-show-maximum-output)
(make-local-variable 'term-ptyp)
(make-local-variable 'term-exec-hook)
(set (make-local-variable 'term-vertical-motion) 'vertical-motion)
(set (make-local-variable 'term-pending-delete-marker) (make-marker))
(make-local-variable 'term-current-face)
......@@ -1144,7 +1129,7 @@ Entry to this mode runs the hooks on `term-mode-hook'."
(while (setq fake-newline (next-single-property-change (point)
(goto-char fake-newline)
(assert (eq ?\n (char-after)))
(cl-assert (eq ?\n (char-after)))
(let ((inhibit-read-only t))
(delete-char 1)))))
......@@ -1329,16 +1314,14 @@ intervention from Emacs, except for the escape character (usually C-c)."
(add-hook 'post-command-hook #'term-goto-process-mark-maybe nil t)
;; Send existing partial line to inferior (without newline).
(let ((pmark (process-mark (get-buffer-process (current-buffer))))
(save-input-sender term-input-sender))
(let ((pmark (process-mark (get-buffer-process (current-buffer)))))
(when (> (point) pmark)
(setq term-input-sender
(symbol-function 'term-send-string))
(add-function :override term-input-sender #'term-send-string)
(setq term-input-sender save-input-sender))))
(remove-function term-input-sender #'term-send-string))))
(defun term-line-mode ()
......@@ -1468,8 +1451,8 @@ buffer. The hook `term-exec-hook' is run after each exec."
;; Jump to the end, and set the process mark.
(goto-char (point-max))
(set-marker (process-mark proc) (point))
(set-process-filter proc 'term-emulate-terminal)
(set-process-sentinel proc 'term-sentinel)
(set-process-filter proc #'term-emulate-terminal)
(set-process-sentinel proc #'term-sentinel)
;; Feed it the startfile.
(when startfile
;;This is guaranteed to wait long enough
......@@ -1598,7 +1581,7 @@ Nil if unknown.")
(when (term--bash-needs-EMACSp)
(push (format "EMACS=%s (term:%s)" emacs-version term-protocol-version)
(apply 'start-process name buffer
(apply #'start-process name buffer
"/bin/sh" "-c"
(format "stty -nl echo rows %d columns %d sane 2>/dev/null;\
if [ $1 = .. ]; then shift; fi; exec \"$@\""
......@@ -2092,7 +2075,7 @@ Argument 0 is the command name."
(let ((n (or nth (1- count)))
(m (if mth (1- (- count mth)) 0)))
(function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " "))))
#'identity (nthcdr n (nreverse (nthcdr m args))) " "))))
;;; Input processing stuff [line mode]
......@@ -2172,10 +2155,7 @@ Similarly for Soar, Scheme, etc."
(not (string-equal (ring-ref term-input-ring 0)
(ring-insert term-input-ring history))
(let ((functions term-input-filter-functions))
(while functions
(funcall (car functions) (concat input "\n"))
(setq functions (cdr functions))))
(run-hook-with-args 'term-input-filter-functions (concat input "\n"))
(setq term-input-ring-index nil)
;; Update the markers before we send the input
......@@ -3009,7 +2989,7 @@ See `term-prompt-regexp'."
(?\C-g ;; (terminfo: bel)
(beep t))
(?\032 ; Emacs specific control sequence.
(funcall term-command-hook
(funcall term-command-function
(substring str (1+ i)
(- ctl-end
......@@ -3103,8 +3083,10 @@ See `term-prompt-regexp'."
(setq term-terminal-undecoded-bytes (substring str (1- i)))
(aset term-terminal-undecoded-bytes 0 ?\r))
(goto-char (point-max)))
;; FIXME: Use (add-function :override (process-filter proc)
(make-local-variable 'term-pager-old-filter)
(setq term-pager-old-filter (process-filter proc))
;; FIXME: Where is `term-pager-filter' set to a function?!
(set-process-filter proc term-pager-filter)
(setq i str-length))
(setq i ctl-end)))))
......@@ -3486,7 +3468,7 @@ The top-most line is line 0."
;; (setq term-current-row 0)
;; (term-goto row col))))
;; Default value for the symbol term-command-hook.
;; Default value for the symbol term-command-function.
(defun term-command-hook (string)
(cond ((equal string "")
......@@ -4040,9 +4022,7 @@ Calls the functions in `term-dynamic-complete-functions' to perform
completion until a function returns non-nil, at which point completion is
assumed to have occurred."
(let ((functions term-dynamic-complete-functions))
(while (and functions (null (funcall (car functions))))
(setq functions (cdr functions)))))
(run-hook-with-args-until-success 'term-dynamic-complete-functions))
(defun term-dynamic-complete-filename ()
......@@ -4142,7 +4122,6 @@ Returns `listed' if a completion listing was shown.
See also `term-dynamic-complete-filename'."
(declare (obsolete completion-in-region "23.2"))
(let* ((completion-ignore-case nil)
(candidates (mapcar (function (lambda (x) (list x))) candidates))
(completions (all-completions stub candidates)))
(cond ((null completions)
(message "No completions of %s" stub)
......@@ -4367,9 +4346,9 @@ well as the newer ports COM10 and higher."
(setq serial-name-history file-name-history))
(when (or (null x) (and (stringp x) (zerop (length x))))
(error "No serial port selected"))
(when (and (not (serial-port-is-file-p))
(not (string-match "\\\\" x)))
(set 'x (concat "\\\\.\\" x)))
(when (not (or (serial-port-is-file-p)
(string-match "\\\\" x)))
(setq x (concat "\\\\.\\" x)))
(defun serial-read-speed ()
......@@ -4423,8 +4402,8 @@ use in that buffer.
(goto-char (point-max))
(set-marker (process-mark process) (point))
(set-process-filter process 'term-emulate-terminal)
(set-process-sentinel process 'term-sentinel))
(set-process-filter process #'term-emulate-terminal)
(set-process-sentinel process #'term-sentinel))
(switch-to-buffer buffer)
......@@ -4561,27 +4540,19 @@ The return value may be nil for a special serial port."
;; term-mode will take care of it. The following example, from shell.el,
;; is typical:
;; (defvar shell-mode-map '())
;; (cond ((not shell-mode-map)
;; (setq shell-mode-map (copy-keymap term-mode-map))
;; (define-key shell-mode-map "\C-c\C-f" 'shell-forward-command)
;; (define-key shell-mode-map "\C-c\C-b" 'shell-backward-command)
;; (define-key shell-mode-map "\t" 'term-dynamic-complete)
;; (define-key shell-mode-map "\M-?"
;; 'term-dynamic-list-filename-completions)))
;; (defun shell-mode ()
;; (interactive)
;; (term-mode)
;; (setq term-prompt-regexp shell-prompt-pattern)
;; (setq major-mode 'shell-mode)
;; (setq mode-name "Shell")
;; (use-local-map shell-mode-map)
;; (make-local-variable 'shell-directory-stack)
;; (setq shell-directory-stack nil)
;; (add-hook 'term-input-filter-functions 'shell-directory-tracker)
;; (run-mode-hooks 'shell-mode-hook))
;; (defvar shell-mode-map
;; (let ((map (make-sparse-keymap)))
;; (define-key map "\C-c\C-f" 'shell-forward-command)
;; (define-key map "\C-c\C-b" 'shell-backward-command)
;; (define-key map "\t" 'term-dynamic-complete)
;; (define-key map "\M-?"
;; 'term-dynamic-list-filename-completions)))
;; (define-derived-mode shell-mode term-mode "Shell"
;; "A shell mode."
;; (setq-local term-prompt-regexp shell-prompt-pattern)
;; (setq-local shell-directory-stack nil)
;; (add-hook 'term-input-filter-functions #'shell-directory-tracker nil t))
;; Completion for term-mode users
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment