comparison lisp/progmodes/sh-script.el @ 51379:f61b3dac769b

(sh-is-quoted-p): New fun. (sh-font-lock-paren): Use it to allow \C in case patterns. (sh-get-indent-info): Check the \n before the line for string-status. (sh-feature): Remove unused var `function'. (sh-get-indent-info): Remove unused variables. (sh-prev-thing): Remove unused vars `going', `n', and `found'. (sh-set-indent): Remove unused var `new-val' and `val0'. (sh-learn-buffer-indent): Remove unused vars `last-pos' and `lines'. (sh-guess-basic-offset): Remove unused var `return' and `j'.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 01 Jun 2003 17:36:41 +0000
parents 575ad90ca254
children 6d06c54cda5d
comparison
equal deleted inserted replaced
51378:140113b35d70 51379:f61b3dac769b
888 (defun sh-font-lock-here-doc (limit) 888 (defun sh-font-lock-here-doc (limit)
889 "Search for a heredoc marker." 889 "Search for a heredoc marker."
890 ;; This looks silly, but it's because `sh-here-doc-re' keeps changing. 890 ;; This looks silly, but it's because `sh-here-doc-re' keeps changing.
891 (re-search-forward sh-here-doc-re limit t)) 891 (re-search-forward sh-here-doc-re limit t))
892 892
893 (defun sh-is-quoted-p (pos)
894 (and (eq (char-before pos) ?\\)
895 (not (sh-is-quoted-p (1- pos)))))
896
893 (defun sh-font-lock-paren (start) 897 (defun sh-font-lock-paren (start)
894 (save-excursion 898 (save-excursion
895 (goto-char start) 899 (goto-char start)
896 ;; Skip through all patterns 900 ;; Skip through all patterns
897 (while 901 (while
898 (progn 902 (progn
899 (forward-comment (- (point-max))) 903 (forward-comment (- (point-max)))
900 ;; Skip through one pattern 904 ;; Skip through one pattern
901 (while 905 (while
902 (or (/= 0 (skip-syntax-backward "w_")) 906 (or (/= 0 (skip-syntax-backward "w_"))
903 (/= 0 (skip-chars-backward "?*/")) 907 (/= 0 (skip-chars-backward "?*/\\"))
908 (and (sh-is-quoted-p (1- (point)))
909 (goto-char (- (point) 2)))
904 (when (memq (char-before) '(?\" ?\')) 910 (when (memq (char-before) '(?\" ?\'))
905 (condition-case nil (progn (backward-sexp 1) t) 911 (condition-case nil (progn (backward-sexp 1) t)
906 (error nil))))) 912 (error nil)))))
907 (forward-comment (- (point-max))) 913 (forward-comment (- (point-max)))
908 (when (eq (char-before) ?|) 914 (when (eq (char-before) ?|)
1534 (if (and (consp (setq val (cdr elt))) 1540 (if (and (consp (setq val (cdr elt)))
1535 (eq (car val) 'eval)) 1541 (eq (car val) 'eval))
1536 (setcdr elt 1542 (setcdr elt
1537 (setq val 1543 (setq val
1538 (eval (if (consp (setq val (cdr val))) 1544 (eval (if (consp (setq val (cdr val)))
1539 (let ((sh-shell (car (cdr val))) 1545 (let ((sh-shell (car (cdr val))))
1540 function)
1541 (if (assq sh-shell list) 1546 (if (assq sh-shell list)
1542 (setcar (cdr val) 1547 (setcar (cdr val)
1543 (list 'quote 1548 (list 'quote
1544 (sh-feature list)))) 1549 (sh-feature list))))
1545 val) 1550 val)
1945 STRING This is ignored for the purposes of calculating 1950 STRING This is ignored for the purposes of calculating
1946 indentation, it is printed in certain cases to help show 1951 indentation, it is printed in certain cases to help show
1947 what the indentation is based on." 1952 what the indentation is based on."
1948 ;; See comments before `sh-kw'. 1953 ;; See comments before `sh-kw'.
1949 (save-excursion 1954 (save-excursion
1950 (let ((prev-kw nil) 1955 (let ((have-result nil)
1951 (prev-stmt nil)
1952 (have-result nil)
1953 depth-bol depth-eol
1954 this-kw 1956 this-kw
1955 (state nil)
1956 state-bol
1957 (depth-prev-bol nil)
1958 start 1957 start
1959 func val 1958 val
1960 (result nil) 1959 (result nil)
1961 prev-lines-indent
1962 (prev-list nil)
1963 (this-list nil)
1964 (align-point nil) 1960 (align-point nil)
1965 prev-line-end x) 1961 prev-line-end x)
1966 (beginning-of-line) 1962 (beginning-of-line)
1967 ;; Note: setting result to t means we are done and will return nil. 1963 ;; Note: setting result to t means we are done and will return nil.
1968 ;;(This function never returns just t.) 1964 ;;(This function never returns just t.)
1969 (cond 1965 (cond
1970 ((or (and (boundp 'font-lock-string-face) 1966 ((or (and (boundp 'font-lock-string-face) (not (bobp))
1971 (eq (get-text-property (point) 'face) font-lock-string-face)) 1967 (eq (get-text-property (1- (point)) 'face)
1968 font-lock-string-face))
1972 (eq (get-text-property (point) 'face) sh-heredoc-face)) 1969 (eq (get-text-property (point) 'face) sh-heredoc-face))
1973 (setq result t) 1970 (setq result t)
1974 (setq have-result t)) 1971 (setq have-result t))
1975 ((looking-at "\\s-*#") ; was (equal this-kw "#") 1972 ((looking-at "\\s-*#") ; was (equal this-kw "#")
1976 (if (bobp) 1973 (if (bobp)
2263 ;; nil - nothing 2260 ;; nil - nothing
2264 ;; a string - possibly a keyword 2261 ;; a string - possibly a keyword
2265 ;; 2262 ;;
2266 (if (bolp) 2263 (if (bolp)
2267 nil 2264 nil
2268 (let ((going t) 2265 (let (c min-point
2269 c n 2266 (start (point)))
2270 min-point
2271 (start (point))
2272 (found nil))
2273 (save-restriction 2267 (save-restriction
2274 (narrow-to-region 2268 (narrow-to-region
2275 (if (sh-this-is-a-continuation) 2269 (if (sh-this-is-a-continuation)
2276 (setq min-point (sh-prev-line nil)) 2270 (setq min-point (sh-prev-line nil))
2277 (save-excursion 2271 (save-excursion
2556 for a new value for it." 2550 for a new value for it."
2557 (interactive) 2551 (interactive)
2558 (sh-must-support-indent) 2552 (sh-must-support-indent)
2559 (let* ((info (sh-get-indent-info)) 2553 (let* ((info (sh-get-indent-info))
2560 (var (sh-get-indent-var-for-line info)) 2554 (var (sh-get-indent-var-for-line info))
2561 val val0 new-val old-val indent-val) 2555 val old-val indent-val)
2562 (if (stringp var) 2556 (if (stringp var)
2563 (message (format "Cannot set indent - %s" var)) 2557 (message (format "Cannot set indent - %s" var))
2564 (setq old-val (symbol-value var)) 2558 (setq old-val (symbol-value var))
2565 (setq val (sh-read-variable var)) 2559 (setq val (sh-read-variable var))
2566 (condition-case nil 2560 (condition-case nil
2751 (save-excursion 2745 (save-excursion
2752 (goto-char (point-min)) 2746 (goto-char (point-min))
2753 (let ((learned-var-list nil) 2747 (let ((learned-var-list nil)
2754 (out-buffer "*indent*") 2748 (out-buffer "*indent*")
2755 (num-diffs 0) 2749 (num-diffs 0)
2756 last-pos
2757 previous-set-info 2750 previous-set-info
2758 (max 17) 2751 (max 17)
2759 vec 2752 vec
2760 msg 2753 msg
2761 (comment-col nil) ;; number if all same, t if seen diff values 2754 (comment-col nil) ;; number if all same, t if seen diff values
2912 2905
2913 (setq learned-var-list 2906 (setq learned-var-list
2914 (append (list (list 'sh-indent-comment comment-col (point-max))) 2907 (append (list (list 'sh-indent-comment comment-col (point-max)))
2915 learned-var-list)) 2908 learned-var-list))
2916 (setq sh-indent-comment comment-col) 2909 (setq sh-indent-comment comment-col)
2917 (let ((name (buffer-name)) 2910 (let ((name (buffer-name)))
2918 (lines (if (and (eq (point-min) 1)
2919 (eq (point-max) (1+ (buffer-size))))
2920 ""
2921 (format "lines %d to %d of "
2922 (1+ (count-lines 1 (point-min)))
2923 (1+ (count-lines 1 (point-max))))))
2924 )
2925 (sh-mark-line "\nLearned variable settings:" nil out-buffer) 2911 (sh-mark-line "\nLearned variable settings:" nil out-buffer)
2926 (if arg 2912 (if arg
2927 ;; Set learned variables to symbolic rather than numeric 2913 ;; Set learned variables to symbolic rather than numeric
2928 ;; values where possible. 2914 ;; values where possible.
2929 (dolist (learned-var (reverse learned-var-list)) 2915 (dolist (learned-var (reverse learned-var-list))
2964 list of numbers - no obvious one, here is a list of one or more 2950 list of numbers - no obvious one, here is a list of one or more
2965 reasonable choices 2951 reasonable choices
2966 nil - we couldn't find a reasonable one." 2952 nil - we couldn't find a reasonable one."
2967 (let* ((max (1- (length vec))) 2953 (let* ((max (1- (length vec)))
2968 (i 1) 2954 (i 1)
2969 (totals (make-vector max 0)) 2955 (totals (make-vector max 0)))
2970 (return nil)
2971 j)
2972 (while (< i max) 2956 (while (< i max)
2973 (aset totals i (+ (aref totals i) (* 4 (aref vec i)))) 2957 (aset totals i (+ (aref totals i) (* 4 (aref vec i))))
2974 (setq j (/ i 2))
2975 (if (zerop (% i 2)) 2958 (if (zerop (% i 2))
2976 (aset totals i (+ (aref totals i) (aref vec (/ i 2))))) 2959 (aset totals i (+ (aref totals i) (aref vec (/ i 2)))))
2977 (if (< (* i 2) max) 2960 (if (< (* i 2) max)
2978 (aset totals i (+ (aref totals i) (aref vec (* i 2))))) 2961 (aset totals i (+ (aref totals i) (aref vec (* i 2)))))
2979 (setq i (1+ i))) 2962 (setq i (1+ i)))