Commit 7fbabaf9 authored by Stefan Monnier's avatar Stefan Monnier

* lisp/progmodes/sh-script.el (sh-mode-map): Don't bind `=`

(sh-shell-initialize-variables): Use sh--assignment-collect on
post-self-insert-hook instead.
(sh--assignment-collect): New function, extracted from sh-assignment.
(sh-assignment): Use it and mark as obsolete.
parent bbadc6e0
Pipeline #3109 failed with stage
in 57 minutes and 37 seconds
...@@ -112,7 +112,7 @@ ...@@ -112,7 +112,7 @@
;; would make this unnecessary; simply learn the values when you visit ;; would make this unnecessary; simply learn the values when you visit
;; the buffer. ;; the buffer.
;; You can do this automatically like this: ;; You can do this automatically like this:
;; (add-hook 'sh-set-shell-hook 'sh-learn-buffer-indent) ;; (add-hook 'sh-set-shell-hook #'sh-learn-buffer-indent)
;; ;;
;; However... `sh-learn-buffer-indent' is extremely slow, ;; However... `sh-learn-buffer-indent' is extremely slow,
;; especially on large-ish buffer. Also, if there are conflicts the ;; especially on large-ish buffer. Also, if there are conflicts the
...@@ -480,7 +480,6 @@ This is buffer-local in every such buffer.") ...@@ -480,7 +480,6 @@ This is buffer-local in every such buffer.")
(define-key map "\C-c>" 'sh-learn-buffer-indent) (define-key map "\C-c>" 'sh-learn-buffer-indent)
(define-key map "\C-c\C-\\" 'sh-backslash-region) (define-key map "\C-c\C-\\" 'sh-backslash-region)
(define-key map "=" 'sh-assignment)
(define-key map "\C-c+" 'sh-add) (define-key map "\C-c+" 'sh-add)
(define-key map "\C-\M-x" 'sh-execute-region) (define-key map "\C-\M-x" 'sh-execute-region)
(define-key map "\C-c\C-x" 'executable-interpret) (define-key map "\C-c\C-x" 'executable-interpret)
...@@ -1059,7 +1058,7 @@ subshells can nest." ...@@ -1059,7 +1058,7 @@ subshells can nest."
(when (< startpos (line-beginning-position)) (when (< startpos (line-beginning-position))
(put-text-property startpos (point) 'syntax-multiline t) (put-text-property startpos (point) 'syntax-multiline t)
(add-hook 'syntax-propertize-extend-region-functions (add-hook 'syntax-propertize-extend-region-functions
'syntax-propertize-multiline nil t)) #'syntax-propertize-multiline nil t))
))) )))
...@@ -1603,25 +1602,25 @@ with your script for an edit-interpret-debug cycle." ...@@ -1603,25 +1602,25 @@ with your script for an edit-interpret-debug cycle."
(setq-local local-abbrev-table sh-mode-abbrev-table) (setq-local local-abbrev-table sh-mode-abbrev-table)
(setq-local comint-dynamic-complete-functions (setq-local comint-dynamic-complete-functions
sh-dynamic-complete-functions) sh-dynamic-complete-functions)
(add-hook 'completion-at-point-functions 'comint-completion-at-point nil t) (add-hook 'completion-at-point-functions #'comint-completion-at-point nil t)
;; we can't look if previous line ended with `\' ;; we can't look if previous line ended with `\'
(setq-local comint-prompt-regexp "^[ \t]*") (setq-local comint-prompt-regexp "^[ \t]*")
(setq-local imenu-case-fold-search nil) (setq-local imenu-case-fold-search nil)
(setq font-lock-defaults (setq font-lock-defaults
'((sh-font-lock-keywords `((sh-font-lock-keywords
sh-font-lock-keywords-1 sh-font-lock-keywords-2) sh-font-lock-keywords-1 sh-font-lock-keywords-2)
nil nil nil nil
((?/ . "w") (?~ . "w") (?. . "w") (?- . "w") (?_ . "w")) nil ((?/ . "w") (?~ . "w") (?. . "w") (?- . "w") (?_ . "w")) nil
(font-lock-syntactic-face-function (font-lock-syntactic-face-function
. sh-font-lock-syntactic-face-function))) . ,#'sh-font-lock-syntactic-face-function)))
(setq-local syntax-propertize-function #'sh-syntax-propertize-function) (setq-local syntax-propertize-function #'sh-syntax-propertize-function)
(add-hook 'syntax-propertize-extend-region-functions (add-hook 'syntax-propertize-extend-region-functions
#'syntax-propertize-multiline 'append 'local) #'syntax-propertize-multiline 'append 'local)
(setq-local skeleton-pair-alist '((?` _ ?`))) (setq-local skeleton-pair-alist '((?` _ ?`)))
(setq-local skeleton-pair-filter-function 'sh-quoted-p) (setq-local skeleton-pair-filter-function #'sh-quoted-p)
(setq-local skeleton-further-elements (setq-local skeleton-further-elements
'((< '(- (min sh-basic-offset (current-column)))))) '((< '(- (min sh-basic-offset (current-column))))))
(setq-local skeleton-filter-function 'sh-feature) (setq-local skeleton-filter-function #'sh-feature)
(setq-local skeleton-newline-indent-rigidly t) (setq-local skeleton-newline-indent-rigidly t)
(setq-local defun-prompt-regexp (setq-local defun-prompt-regexp
(concat (concat
...@@ -2408,12 +2407,12 @@ whose value is the shell name (don't quote it)." ...@@ -2408,12 +2407,12 @@ whose value is the shell name (don't quote it)."
(message "setting up indent stuff") (message "setting up indent stuff")
;; sh-mode has already made indent-line-function local ;; sh-mode has already made indent-line-function local
;; but do it in case this is called before that. ;; but do it in case this is called before that.
(setq-local indent-line-function 'sh-indent-line)) (setq-local indent-line-function #'sh-indent-line))
(if sh-make-vars-local (if sh-make-vars-local
(sh-make-vars-local)) (sh-make-vars-local))
(message "Indentation setup for shell type %s" sh-shell)) (message "Indentation setup for shell type %s" sh-shell))
(message "No indentation for this shell type.") (message "No indentation for this shell type.")
(setq-local indent-line-function 'sh-basic-indent-line)) (setq-local indent-line-function #'sh-basic-indent-line))
(when font-lock-mode (when font-lock-mode
(setq font-lock-set-defaults nil) (setq font-lock-set-defaults nil)
(font-lock-set-defaults) (font-lock-set-defaults)
...@@ -3586,7 +3585,7 @@ so that `occur-next' and `occur-prev' will work." ...@@ -3586,7 +3585,7 @@ so that `occur-next' and `occur-prev' will work."
;; (insert ")\n") ;; (insert ")\n")
;; ))) ;; )))
;; ;;
;; (add-hook 'sh-learned-buffer-hook 'what-i-learned) ;; (add-hook 'sh-learned-buffer-hook #'what-i-learned)
;; Originally this was sh-learn-region-indent (beg end) ;; Originally this was sh-learn-region-indent (beg end)
...@@ -4055,7 +4054,8 @@ Add these variables to `sh-shell-variables'." ...@@ -4055,7 +4054,8 @@ Add these variables to `sh-shell-variables'."
(goto-char (point-min)) (goto-char (point-min))
(setq sh-shell-variables-initialized t) (setq sh-shell-variables-initialized t)
(while (search-forward "=" nil t) (while (search-forward "=" nil t)
(sh-assignment 0))) (sh--assignment-collect)))
(add-hook 'post-self-insert-hook #'sh--assignment-collect nil t)
(message "Scanning buffer `%s' for variable assignments...done" (message "Scanning buffer `%s' for variable assignments...done"
(buffer-name))) (buffer-name)))
...@@ -4328,20 +4328,23 @@ option followed by a colon `:' if the option accepts an argument." ...@@ -4328,20 +4328,23 @@ option followed by a colon `:' if the option accepts an argument."
(put 'sh-assignment 'delete-selection t)
(defun sh-assignment (arg) (defun sh-assignment (arg)
"Remember preceding identifier for future completion and do self-insert." "Remember preceding identifier for future completion and do self-insert."
(interactive "p") (interactive "p")
(declare (obsolete nil "27.1"))
(self-insert-command arg) (self-insert-command arg)
(if (<= arg 1) (sh--assignment-collect))
(sh-remember-variable
(save-excursion (defun sh--assignment-collect ()
(if (re-search-forward (sh-feature sh-assignment-regexp) (sh-remember-variable
(prog1 (point) (save-excursion
(beginning-of-line 1)) (if (re-search-forward (sh-feature sh-assignment-regexp)
t) (prog1 (point)
(match-string 1)))))) (beginning-of-line 1))
t)
(match-string 1)))))
(put 'sh-assignment 'delete-selection t)
(defun sh-maybe-here-document (arg) (defun sh-maybe-here-document (arg)
"Insert self. Without prefix, following unquoted `<' inserts here document. "Insert self. Without prefix, following unquoted `<' inserts here document.
......
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