comparison lisp/progmodes/sh-script.el @ 64266:a634aa374675

(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.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 13 Jul 2005 04:55:42 +0000
parents 18a818a2ee7c
children 7fb2b79e33d0 fbb2bea03df9
comparison
equal deleted inserted replaced
64265:dde987aec664 64266:a634aa374675
2031 2031
2032 (unless have-result 2032 (unless have-result
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")
2044 (setq this-kw (sh-get-kw))) 2053 (setq this-kw (sh-get-kw)))
2045 2054
2128 (setq result (append (list (list t align-point)) result)) 2137 (setq result (append (list (list t align-point)) result))
2129 ) 2138 )
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))
2140 (sh-debug "result is: %s" result) 2148 (sh-debug "result is: %s" result)
2141 result 2149 result
2693 2701
2694 2702
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)
2706 "Insert MESSAGE referring to location POINT in current buffer into BUFFER. 2712 "Insert MESSAGE referring to location POINT in current buffer into BUFFER.
2707 Buffer BUFFER is in `occur-mode'. 2713 Buffer BUFFER is in `occur-mode'.
2970 (sh-set-var-value var val))))) 2976 (sh-set-var-value var val)))))
2971 (dolist (learned-var (reverse learned-var-list)) 2977 (dolist (learned-var (reverse learned-var-list))
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)
2980 (format "%d indentation variable%s different values%s\n\n" 2985 (format "%d indentation variable%s different values%s\n\n"
2981 num-diffs 2986 num-diffs
3242 CODE can be nil, t or `lambda'. 3247 CODE can be nil, t or `lambda'.
3243 nil means to return the best completion of STRING, or nil if there is none. 3248 nil means to return the best completion of STRING, or nil if there is none.
3244 t means to return a list of all possible completions of STRING. 3249 t 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)
3252 (let ((name 3256 (let ((name
3253 (substring var 0 (string-match "=" var)))) 3257 (substring var 0 (string-match "=" var))))