aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2005-07-13 04:55:42 +0000
committerStefan Monnier2005-07-13 04:55:42 +0000
commit090475f391ceb175048e0610bcfabffd8d5a0241 (patch)
treef7c51aea13e58c37040df5a11e8eaf5c2b3f37c8
parent8a08764f7a72eb062a85733b045fb50291d6aee9 (diff)
downloademacs-090475f391ceb175048e0610bcfabffd8d5a0241.tar.gz
emacs-090475f391ceb175048e0610bcfabffd8d5a0241.zip
(sh-get-indent-info): Only indent a continuation line if SPC or TAB precedes \.
(sh-get-indent-info): Simplify. (sh-mark-init, sh-learn-buffer-indent, sh-add-completer): with-current-buffer.
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/progmodes/sh-script.el38
2 files changed, 24 insertions, 17 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 4b80ab3f93d..03b494adc04 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2181,6 +2181,9 @@ line is left untouched.
2181The function `c-toggle-syntactic-indentation' can be used to toggle 2181The function `c-toggle-syntactic-indentation' can be used to toggle
2182syntactic indentation. 2182syntactic indentation.
2183 2183
2184** In sh-script, a continuation line is only indented if the backslash was
2185preceded by a SPC or a TAB.
2186
2184--- 2187---
2185** Perl mode has a new variable `perl-indent-continued-arguments'. 2188** Perl mode has a new variable `perl-indent-continued-arguments'.
2186 2189
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 3261f7bcc98..99e367a8633 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -2033,11 +2033,20 @@ STRING This is ignored for the purposes of calculating
2033 ;; Continuation lines are handled specially 2033 ;; Continuation lines are handled specially
2034 (if (sh-this-is-a-continuation) 2034 (if (sh-this-is-a-continuation)
2035 (progn 2035 (progn
2036 ;; We assume the line being continued is already 2036 (setq result
2037 ;; properly indented... 2037 (if (save-excursion
2038 ;; (setq prev-line-end (sh-prev-line)) 2038 (beginning-of-line)
2039 (setq align-point (sh-prev-line nil)) 2039 (not (memq (char-before (- (point) 2)) '(?\s ?\t))))
2040 (setq result (list '(+ sh-indent-for-continuation))) 2040 ;; By convention, if the continuation \ is not
2041 ;; preceded by a SPC or a TAB it means that the line
2042 ;; is cut at a place where spaces cannot be freely
2043 ;; added/removed. I.e. do not indent the line.
2044 (list '(= nil))
2045 ;; We assume the line being continued is already
2046 ;; properly indented...
2047 ;; (setq prev-line-end (sh-prev-line))
2048 (setq align-point (sh-prev-line nil))
2049 (list '(+ sh-indent-for-continuation))))
2041 (setq have-result t)) 2050 (setq have-result t))
2042 (beginning-of-line) 2051 (beginning-of-line)
2043 (skip-chars-forward " \t") 2052 (skip-chars-forward " \t")
@@ -2130,10 +2139,9 @@ STRING This is ignored for the purposes of calculating
2130 (sh-debug "result is now: %s" result) 2139 (sh-debug "result is now: %s" result)
2131 2140
2132 (or result 2141 (or result
2133 (if prev-line-end 2142 (setq result (list (if prev-line-end
2134 (setq result (list (list t prev-line-end))) 2143 (list t prev-line-end)
2135 (setq result (list (list '= 'sh-first-lines-indent))) 2144 (list '= 'sh-first-lines-indent)))))
2136 ))
2137 2145
2138 (if (eq result t) 2146 (if (eq result t)
2139 (setq result nil)) 2147 (setq result nil))
@@ -2695,11 +2703,9 @@ unless optional argument ARG (the prefix when interactive) is non-nil."
2695 2703
2696(defun sh-mark-init (buffer) 2704(defun sh-mark-init (buffer)
2697 "Initialize a BUFFER to be used by `sh-mark-line'." 2705 "Initialize a BUFFER to be used by `sh-mark-line'."
2698 (save-excursion 2706 (with-current-buffer (get-buffer-create buffer)
2699 (set-buffer (get-buffer-create buffer))
2700 (erase-buffer) 2707 (erase-buffer)
2701 (occur-mode) 2708 (occur-mode)))
2702 ))
2703 2709
2704 2710
2705(defun sh-mark-line (message point buffer &optional add-linenum occur-point) 2711(defun sh-mark-line (message point buffer &optional add-linenum occur-point)
@@ -2972,8 +2978,7 @@ This command can often take a long time to run."
2972 (let ((var (car learned-var))) 2978 (let ((var (car learned-var)))
2973 (sh-mark-line (format " %s %s" var (symbol-value var)) 2979 (sh-mark-line (format " %s %s" var (symbol-value var))
2974 (nth 2 learned-var) out-buffer))) 2980 (nth 2 learned-var) out-buffer)))
2975 (save-excursion 2981 (with-current-buffer out-buffer
2976 (set-buffer out-buffer)
2977 (goto-char (point-min)) 2982 (goto-char (point-min))
2978 (insert 2983 (insert
2979 (format "Indentation values for buffer %s.\n" name) 2984 (format "Indentation values for buffer %s.\n" name)
@@ -3244,8 +3249,7 @@ nil means to return the best completion of STRING, or nil if there is none.
3244t means to return a list of all possible completions of STRING. 3249t means to return a list of all possible completions of STRING.
3245`lambda' means to return t if STRING is a valid completion as it stands." 3250`lambda' means to return t if STRING is a valid completion as it stands."
3246 (let ((sh-shell-variables 3251 (let ((sh-shell-variables
3247 (save-excursion 3252 (with-current-buffer sh-add-buffer
3248 (set-buffer sh-add-buffer)
3249 (or sh-shell-variables-initialized 3253 (or sh-shell-variables-initialized
3250 (sh-shell-initialize-variables)) 3254 (sh-shell-initialize-variables))
3251 (nconc (mapcar (lambda (var) 3255 (nconc (mapcar (lambda (var)