emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-24 r117292: Fix some indentation problem with \; and


From: Stefan Monnier
Subject: [Emacs-diffs] emacs-24 r117292: Fix some indentation problem with \; and pipes.
Date: Tue, 24 Jun 2014 20:16:17 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117292
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17842
committer: Stefan Monnier <address@hidden>
branch nick: emacs-24
timestamp: Tue 2014-06-24 16:16:10 -0400
message:
  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.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/progmodes/sh-script.el    shscript.el-20091113204419-o5vbwnq5f7feedwu-727
  test/indent/shell.sh           shell.sh-20110209185043-iuyrh0is1gz0s4w6-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-06-24 07:10:47 +0000
+++ b/lisp/ChangeLog    2014-06-24 20:16:10 +0000
@@ -1,3 +1,13 @@
+2014-06-24  Stefan Monnier  <address@hidden>
+
+       Fix some indentation problem with \; and pipes (bug#17842).
+       * 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.
+
 2014-06-24  Eli Zaretskii  <address@hidden>
 
        * international/fontset.el (script-representative-chars):

=== modified file 'lisp/progmodes/sh-script.el'
--- a/lisp/progmodes/sh-script.el       2014-06-20 14:23:30 +0000
+++ b/lisp/progmodes/sh-script.el       2014-06-24 20:16:10 +0000
@@ -466,6 +466,9 @@
        ?~ "_"
        ?, "_"
        ?= "."
+       ?\; "."
+       ?| "."
+       ?& "."
        ?< "."
        ?> ".")
   "The syntax table to use for Shell-Script mode.
@@ -1837,6 +1840,40 @@
    ((equal tok "in") (sh-smie--sh-keyword-in-p))
    (t (sh-smie--keyword-p))))
 
+(defun sh-smie--default-forward-token ()
+  (forward-comment (point-max))
+  (buffer-substring-no-properties
+   (point)
+   (progn (if (zerop (skip-syntax-forward "."))
+              (while (progn (skip-syntax-forward "w_'")
+                            (looking-at "\\\\"))
+                (forward-char 2)))
+          (point))))
+
+(defun sh-smie--default-backward-token ()
+  (forward-comment (- (point)))
+  (let ((pos (point))
+        (n (skip-syntax-backward ".")))
+    (if (or (zerop n)
+            (and (eq n -1)
+                 (let ((p (point)))
+                   (if (eq -1 (% (skip-syntax-backward "\\") 2))
+                       t
+                     (goto-char p)
+                     nil))))
+        (while
+            (progn (skip-syntax-backward "w_'")
+                   (or (not (zerop (skip-syntax-backward "\\")))
+                       (when (eq ?\\ (char-before (1- (point))))
+                         (let ((p (point)))
+                           (forward-char -1)
+                           (if (eq -1 (% (skip-syntax-backward "\\") 2))
+                               t
+                             (goto-char p)
+                             nil))))))
+      (goto-char (- (point) (% (skip-syntax-backward "\\") 2))))
+    (buffer-substring-no-properties (point) pos)))
+
 (defun sh-smie-sh-forward-token ()
   (if (and (looking-at "[ \t]*\\(?:#\\|\\(\\s|\\)\\|$\\)")
            (save-excursion
@@ -1865,7 +1902,7 @@
         tok))
      (t
       (let* ((pos (point))
-             (tok (smie-default-forward-token)))
+             (tok (sh-smie--default-forward-token)))
         (cond
          ((equal tok ")") "case-)")
          ((equal tok "(") "case-(")
@@ -1909,7 +1946,7 @@
       (goto-char (match-beginning 1))
       (match-string-no-properties 1))
      (t
-      (let ((tok (smie-default-backward-token)))
+      (let ((tok (sh-smie--default-backward-token)))
         (cond
          ((equal tok ")") "case-)")
          ((equal tok "(") "case-(")
@@ -1939,18 +1976,18 @@
     (`(:after . "case-)") (- (sh-var-value 'sh-indent-for-case-alt)
                              (sh-var-value 'sh-indent-for-case-label)))
     ((and `(:before . ,_)
-          (guard (when sh-indent-after-continuation
-                   (save-excursion
-                     (ignore-errors
-                       (skip-chars-backward " \t")
-                       (sh-smie--looking-back-at-continuation-p))))))
-     ;; After a line-continuation, make sure the rest is indented.
-     (let* ((sh-indent-after-continuation nil)
-            (indent (smie-indent-calculate))
-            (initial (sh-smie--continuation-start-indent)))
-       (when (and (numberp indent) (numberp initial)
-                  (<= indent initial))
-         `(column . ,(+ initial sh-indentation)))))
+          ;; After a line-continuation, make sure the rest is indented.
+          (guard sh-indent-after-continuation)
+          (guard (save-excursion
+                   (ignore-errors
+                     (skip-chars-backward " \t")
+                     (sh-smie--looking-back-at-continuation-p))))
+          (let initial (sh-smie--continuation-start-indent))
+          (guard (let* ((sh-indent-after-continuation nil)
+                        (indent (smie-indent-calculate)))
+                   (and (numberp indent) (numberp initial)
+                        (<= indent initial)))))
+     `(column . ,(+ initial sh-indentation)))
     (`(:before . ,(or `"(" `"{" `"["))
      (when (smie-rule-hanging-p)
        (if (not (smie-rule-prev-p "&&" "||" "|"))
@@ -1974,7 +2011,12 @@
                             (smie-rule-bolp))))
                  (current-column)
                (smie-indent-calculate)))))
-    (`(:after . ,(or `"|" `"&&" `"||")) (if (smie-rule-parent-p token) nil 4))
+    (`(:before . ,(or `"|" `"&&" `"||"))
+     (unless (smie-rule-parent-p token)
+       (smie-backward-sexp token)
+       `(column . ,(+ (funcall smie-rules-function :elem 'basic)
+                      (smie-indent-virtual)))))
+
     ;; Attempt at backward compatibility with the old config variables.
     (`(:before . "fi") (sh-var-value 'sh-indent-for-fi))
     (`(:before . "done") (sh-var-value 'sh-indent-for-done))
@@ -2095,7 +2137,7 @@
      ;;    tok))
      (t
       (let* ((pos (point))
-             (tok (smie-default-forward-token)))
+             (tok (sh-smie--default-forward-token)))
         (cond
          ;; ((equal tok ")") "case-)")
          ((and tok (string-match "\\`[a-z]" tok)
@@ -2136,7 +2178,7 @@
      ;;  (goto-char (match-beginning 1))
      ;;  (match-string-no-properties 1))
      (t
-      (let ((tok (smie-default-backward-token)))
+      (let ((tok (sh-smie--default-backward-token)))
         (cond
          ;; ((equal tok ")") "case-)")
          ((and tok (string-match "\\`[a-z]" tok)

=== modified file 'test/indent/shell.sh'
--- a/test/indent/shell.sh      2014-06-20 14:23:30 +0000
+++ b/test/indent/shell.sh      2014-06-24 20:16:10 +0000
@@ -41,6 +41,13 @@
     }
 done
 
+filter_3 ()                     # bug#17842
+{
+    tr -d '"`' | tr '  ' ' ' | \
+        awk -F\; -f filter.awk | \
+       grep -v "^," | sort -t, -k2,2
+}
+
 echo -n $(( 5 << 2 ))
 # This should not be treated as a heredoc (bug#12770).
 2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]