emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/emacs-24 r108236: * lisp/emacs-lisp/smie.el


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/emacs-24 r108236: * lisp/emacs-lisp/smie.el (smie-indent--bolp-1): New function.
Date: Fri, 02 Nov 2012 01:46:18 -0000
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 108236
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Tue 2012-05-15 09:25:03 -0400
message:
  * lisp/emacs-lisp/smie.el (smie-indent--bolp-1): New function.
  (smie-indent-keyword): Use it.
modified:
  lisp/ChangeLog
  lisp/emacs-lisp/smie.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-05-14 20:39:14 +0000
+++ b/lisp/ChangeLog    2012-05-15 13:25:03 +0000
@@ -1,3 +1,8 @@
+2012-05-15  Stefan Monnier  <address@hidden>
+
+       * emacs-lisp/smie.el (smie-indent--bolp-1): New function.
+       (smie-indent-keyword): Use it.
+
 2012-05-14  Stefan Merten  <address@hidden>
 
        * textmodes/rst.el (rst-re-alist): Fix loading (bug#11462).
@@ -15,8 +20,8 @@
 
 2012-05-14  Stefan Monnier  <address@hidden>
 
-       * shell.el (shell-parse-pcomplete-arguments): Obey
-       pcomplete-arg-quote-list inside double-quoted args (Bug#11348).
+       * shell.el (shell-parse-pcomplete-arguments):
+       Obey pcomplete-arg-quote-list inside double-quoted args (Bug#11348).
 
 2012-05-14  Wolfgang Jenkner  <address@hidden>
 

=== modified file 'lisp/emacs-lisp/smie.el'
--- a/lisp/emacs-lisp/smie.el   2012-05-13 16:04:37 +0000
+++ b/lisp/emacs-lisp/smie.el   2012-05-15 13:25:03 +0000
@@ -688,6 +688,7 @@
     is too high.  FORW-LEVEL is the forw-level of TOKEN,
     POS is its start position in the buffer.
   (t POS TOKEN): same thing when we bump on the wrong side of a paren.
+    Instead of t, the `car' can also be some other non-nil non-number value.
   (nil POS TOKEN): we skipped over a paren-like pair.
   nil: we skipped over an identifier, matched parentheses, ..."
   (catch 'return
@@ -795,6 +796,7 @@
     is too high.  LEFT-LEVEL is the left-level of TOKEN,
     POS is its start position in the buffer.
   (t POS TOKEN): same thing but for an open-paren or the beginning of buffer.
+    Instead of t, the `car' can also be some other non-nil non-number value.
   (nil POS TOKEN): we skipped over a paren-like pair.
   nil: we skipped over an identifier, matched parentheses, ..."
   (smie-next-sexp
@@ -814,7 +816,8 @@
   (RIGHT-LEVEL POS TOKEN): we couldn't skip TOKEN because its left-level
     is too high.  RIGHT-LEVEL is the right-level of TOKEN,
     POS is its end position in the buffer.
-  (t POS TOKEN): same thing but for an open-paren or the beginning of buffer.
+  (t POS TOKEN): same thing but for a close-paren or the end of buffer.
+    Instead of t, the `car' can also be some other non-nil non-number value.
   (nil POS TOKEN): we skipped over a paren-like pair.
   nil: we skipped over an identifier, matched parentheses, ..."
   (smie-next-sexp
@@ -1076,6 +1079,16 @@
   "Return non-nil if the current token is the first on the line."
   (save-excursion (skip-chars-backward " \t") (bolp)))
 
+(defun smie-indent--bolp-1 ()
+  ;; Like smie-indent--bolp but also returns non-nil if it's the first
+  ;; non-comment token.  Maybe we should simply always use this?
+  "Return non-nil if the current token is the first on the line.
+Comments are treated as spaces."
+  (let ((bol (line-beginning-position)))
+    (save-excursion
+      (forward-comment (- (point)))
+      (<= (point) bol))))
+
 ;; Dynamically scoped.
 (defvar smie--parent) (defvar smie--after) (defvar smie--token)
 
@@ -1352,9 +1365,12 @@
         ;; - middle-of-line: "trust current position".
         (cond
          ((smie-indent--rule :before token))
-         ((smie-indent--bolp)           ;I.e. non-virtual indent.
+         ((smie-indent--bolp-1)         ;I.e. non-virtual indent.
           ;; For an open-paren-like thingy at BOL, always indent only
           ;; based on other rules (typically smie-indent-after-keyword).
+          ;; FIXME: we do the same if after a comment, since we may be trying
+          ;; to compute the indentation of this comment and we shouldn't indent
+          ;; based on the indentation of subsequent code.
           nil)
          (t
           ;; By default use point unless we're hanging.
@@ -1455,6 +1471,12 @@
        (save-excursion
          (forward-comment (point-max))
          (skip-chars-forward " \t\r\n")
+         ;; FIXME: We assume here that smie-indent-calculate will compute the
+         ;; indentation of the next token based on text before the comment, but
+         ;; this is not guaranteed, so maybe we should let
+         ;; smie-indent-calculate return some info about which buffer position
+         ;; was used as the "indentation base" and check that this base is
+         ;; before `pos'.
          (smie-indent-calculate))))
 
 (defun smie-indent-comment-continue ()


reply via email to

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