aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorStefan Monnier2014-06-24 16:16:10 -0400
committerStefan Monnier2014-06-24 16:16:10 -0400
commit370ceb22102e02a25516e43a61da0c9a9d6e1579 (patch)
tree1d9dec72a58f9eec131fcd4b63fd80672a0c3679 /lisp/progmodes
parent2394ef283c781297f3a1da79c8c8c92ca9d1b5e5 (diff)
downloademacs-370ceb22102e02a25516e43a61da0c9a9d6e1579.tar.gz
emacs-370ceb22102e02a25516e43a61da0c9a9d6e1579.zip
Fix some indentation problem with \; and pipes.
* lisp/progmodes/sh-script.el (sh-mode-syntax-table): Set syntax of ;|&. (sh-smie--default-forward-token, sh-smie--default-backward-token): New functions. (sh-smie-sh-forward-token, sh-smie-sh-backward-token) (sh-smie-rc-forward-token, sh-smie-rc-backward-token): Use them. (sh-smie-sh-rules): Fix indentation of a pipe at BOL. Fixes: debbugs:17842
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/sh-script.el76
1 files changed, 59 insertions, 17 deletions
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 4db462594dc..1601b6c81ae 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -466,6 +466,9 @@ the car and cdr are the same symbol.")
466 ?~ "_" 466 ?~ "_"
467 ?, "_" 467 ?, "_"
468 ?= "." 468 ?= "."
469 ?\; "."
470 ?| "."
471 ?& "."
469 ?< "." 472 ?< "."
470 ?> ".") 473 ?> ".")
471 "The syntax table to use for Shell-Script mode. 474 "The syntax table to use for Shell-Script mode.
@@ -1837,6 +1840,40 @@ Does not preserve point."
1837 ((equal tok "in") (sh-smie--sh-keyword-in-p)) 1840 ((equal tok "in") (sh-smie--sh-keyword-in-p))
1838 (t (sh-smie--keyword-p)))) 1841 (t (sh-smie--keyword-p))))
1839 1842
1843(defun sh-smie--default-forward-token ()
1844 (forward-comment (point-max))
1845 (buffer-substring-no-properties
1846 (point)
1847 (progn (if (zerop (skip-syntax-forward "."))
1848 (while (progn (skip-syntax-forward "w_'")
1849 (looking-at "\\\\"))
1850 (forward-char 2)))
1851 (point))))
1852
1853(defun sh-smie--default-backward-token ()
1854 (forward-comment (- (point)))
1855 (let ((pos (point))
1856 (n (skip-syntax-backward ".")))
1857 (if (or (zerop n)
1858 (and (eq n -1)
1859 (let ((p (point)))
1860 (if (eq -1 (% (skip-syntax-backward "\\") 2))
1861 t
1862 (goto-char p)
1863 nil))))
1864 (while
1865 (progn (skip-syntax-backward "w_'")
1866 (or (not (zerop (skip-syntax-backward "\\")))
1867 (when (eq ?\\ (char-before (1- (point))))
1868 (let ((p (point)))
1869 (forward-char -1)
1870 (if (eq -1 (% (skip-syntax-backward "\\") 2))
1871 t
1872 (goto-char p)
1873 nil))))))
1874 (goto-char (- (point) (% (skip-syntax-backward "\\") 2))))
1875 (buffer-substring-no-properties (point) pos)))
1876
1840(defun sh-smie-sh-forward-token () 1877(defun sh-smie-sh-forward-token ()
1841 (if (and (looking-at "[ \t]*\\(?:#\\|\\(\\s|\\)\\|$\\)") 1878 (if (and (looking-at "[ \t]*\\(?:#\\|\\(\\s|\\)\\|$\\)")
1842 (save-excursion 1879 (save-excursion
@@ -1865,7 +1902,7 @@ Does not preserve point."
1865 tok)) 1902 tok))
1866 (t 1903 (t
1867 (let* ((pos (point)) 1904 (let* ((pos (point))
1868 (tok (smie-default-forward-token))) 1905 (tok (sh-smie--default-forward-token)))
1869 (cond 1906 (cond
1870 ((equal tok ")") "case-)") 1907 ((equal tok ")") "case-)")
1871 ((equal tok "(") "case-(") 1908 ((equal tok "(") "case-(")
@@ -1909,7 +1946,7 @@ Does not preserve point."
1909 (goto-char (match-beginning 1)) 1946 (goto-char (match-beginning 1))
1910 (match-string-no-properties 1)) 1947 (match-string-no-properties 1))
1911 (t 1948 (t
1912 (let ((tok (smie-default-backward-token))) 1949 (let ((tok (sh-smie--default-backward-token)))
1913 (cond 1950 (cond
1914 ((equal tok ")") "case-)") 1951 ((equal tok ")") "case-)")
1915 ((equal tok "(") "case-(") 1952 ((equal tok "(") "case-(")
@@ -1939,18 +1976,18 @@ May return nil if the line should not be treated as continued."
1939 (`(:after . "case-)") (- (sh-var-value 'sh-indent-for-case-alt) 1976 (`(:after . "case-)") (- (sh-var-value 'sh-indent-for-case-alt)
1940 (sh-var-value 'sh-indent-for-case-label))) 1977 (sh-var-value 'sh-indent-for-case-label)))
1941 ((and `(:before . ,_) 1978 ((and `(:before . ,_)
1942 (guard (when sh-indent-after-continuation 1979 ;; After a line-continuation, make sure the rest is indented.
1943 (save-excursion 1980 (guard sh-indent-after-continuation)
1944 (ignore-errors 1981 (guard (save-excursion
1945 (skip-chars-backward " \t") 1982 (ignore-errors
1946 (sh-smie--looking-back-at-continuation-p)))))) 1983 (skip-chars-backward " \t")
1947 ;; After a line-continuation, make sure the rest is indented. 1984 (sh-smie--looking-back-at-continuation-p))))
1948 (let* ((sh-indent-after-continuation nil) 1985 (let initial (sh-smie--continuation-start-indent))
1949 (indent (smie-indent-calculate)) 1986 (guard (let* ((sh-indent-after-continuation nil)
1950 (initial (sh-smie--continuation-start-indent))) 1987 (indent (smie-indent-calculate)))
1951 (when (and (numberp indent) (numberp initial) 1988 (and (numberp indent) (numberp initial)
1952 (<= indent initial)) 1989 (<= indent initial)))))
1953 `(column . ,(+ initial sh-indentation))))) 1990 `(column . ,(+ initial sh-indentation)))
1954 (`(:before . ,(or `"(" `"{" `"[")) 1991 (`(:before . ,(or `"(" `"{" `"["))
1955 (when (smie-rule-hanging-p) 1992 (when (smie-rule-hanging-p)
1956 (if (not (smie-rule-prev-p "&&" "||" "|")) 1993 (if (not (smie-rule-prev-p "&&" "||" "|"))
@@ -1974,7 +2011,12 @@ May return nil if the line should not be treated as continued."
1974 (smie-rule-bolp)))) 2011 (smie-rule-bolp))))
1975 (current-column) 2012 (current-column)
1976 (smie-indent-calculate))))) 2013 (smie-indent-calculate)))))
1977 (`(:after . ,(or `"|" `"&&" `"||")) (if (smie-rule-parent-p token) nil 4)) 2014 (`(:before . ,(or `"|" `"&&" `"||"))
2015 (unless (smie-rule-parent-p token)
2016 (smie-backward-sexp token)
2017 `(column . ,(+ (funcall smie-rules-function :elem 'basic)
2018 (smie-indent-virtual)))))
2019
1978 ;; Attempt at backward compatibility with the old config variables. 2020 ;; Attempt at backward compatibility with the old config variables.
1979 (`(:before . "fi") (sh-var-value 'sh-indent-for-fi)) 2021 (`(:before . "fi") (sh-var-value 'sh-indent-for-fi))
1980 (`(:before . "done") (sh-var-value 'sh-indent-for-done)) 2022 (`(:before . "done") (sh-var-value 'sh-indent-for-done))
@@ -2095,7 +2137,7 @@ Point should be before the newline."
2095 ;; tok)) 2137 ;; tok))
2096 (t 2138 (t
2097 (let* ((pos (point)) 2139 (let* ((pos (point))
2098 (tok (smie-default-forward-token))) 2140 (tok (sh-smie--default-forward-token)))
2099 (cond 2141 (cond
2100 ;; ((equal tok ")") "case-)") 2142 ;; ((equal tok ")") "case-)")
2101 ((and tok (string-match "\\`[a-z]" tok) 2143 ((and tok (string-match "\\`[a-z]" tok)
@@ -2136,7 +2178,7 @@ Point should be before the newline."
2136 ;; (goto-char (match-beginning 1)) 2178 ;; (goto-char (match-beginning 1))
2137 ;; (match-string-no-properties 1)) 2179 ;; (match-string-no-properties 1))
2138 (t 2180 (t
2139 (let ((tok (smie-default-backward-token))) 2181 (let ((tok (sh-smie--default-backward-token)))
2140 (cond 2182 (cond
2141 ;; ((equal tok ")") "case-)") 2183 ;; ((equal tok ")") "case-)")
2142 ((and tok (string-match "\\`[a-z]" tok) 2184 ((and tok (string-match "\\`[a-z]" tok)