emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/phps-mode 287d934 077/405: Updated comments are made un


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 287d934 077/405: Updated comments are made un-tested function for moving token positions
Date: Sat, 13 Jul 2019 09:59:47 -0400 (EDT)

branch: externals/phps-mode
commit 287d9340f9f3c15401f0773925e07259c9d8aec0
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>

    Updated comments are made un-tested function for moving token positions
---
 phps-functions.el | 34 ++++++++++++++++++++--------------
 phps-lexer.el     | 20 ++++++++++++++++++++
 2 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/phps-functions.el b/phps-functions.el
index 0e84dc5..107b927 100644
--- a/phps-functions.el
+++ b/phps-functions.el
@@ -114,26 +114,32 @@
 
                   (setq indent-level (- indent-level (- indent-start 
indent-end))))))
 
+            ;; If this line is part of a doc-comment increase indent with one 
unit
             (when in-doc-comment
               (setq indent-adjust 1))
 
-            (let ((indent-sum (+ (* indent-level tab-width) indent-adjust)))
-              (when (not (equal indent-sum (current-indentation)))
-                ;; (message "Indenting to %s current column %s" indent-sum 
(current-indentation))
-                ;; (message "inside scripting, start: %s, end: %s, indenting 
to column %s " start end indent-level)
+            (let ((indent-sum (+ (* indent-level tab-width) indent-adjust))
+                  current-indentation (current-indentation))
 
-                ;; TODO When indent is changed the trailing tokens just need 
to adjust their token positions, this will improve speed of indent-region a lot
-                (indent-line-to indent-sum)
+              ;; Only continue if current indentation is wrong
+              (when (not (equal indent-sum current-indentation))
+                (let ((indent-diff (- current-indentation indent-sum)))
+                  ;; (message "Indenting to %s current column %s" indent-sum 
(current-indentation))
+                  ;; (message "inside scripting, start: %s, end: %s, indenting 
to column %s " start end indent-level)
 
-                (let ((line-start (line-beginning-position)))
+                  (indent-line-to indent-sum)
 
-                  ;; Set point of change if it's not set or if it's larger 
than current point
-                  (when (or (not phps-mode/buffer-changes--start)
-                            (< line-start phps-mode/buffer-changes--start))
-                    ;; (message "Setting changes start from %s to %s" 
phps-mode/buffer-changes--start start)
-                    (setq phps-mode/buffer-changes--start line-start))
-                  
-                  (phps-mode/run-incremental-lex))))))))))
+                  ;; TODO When indent is changed the trailing tokens just need 
to adjust their token positions, this will improve speed of indent-region a lot
+
+                  (let ((line-start (line-beginning-position)))
+
+                    ;; Set point of change if it's not set or if it's larger 
than current point
+                    (when (or (not phps-mode/buffer-changes--start)
+                              (< line-start phps-mode/buffer-changes--start))
+                      ;; (message "Setting changes start from %s to %s" 
phps-mode/buffer-changes--start start)
+                      (setq phps-mode/buffer-changes--start line-start))
+                    
+                    (phps-mode/run-incremental-lex)))))))))))
 
 ;; TODO Implement this?
 (defun phps-mode/indent-region ()
diff --git a/phps-lexer.el b/phps-lexer.el
index 70359c0..8e41347 100644
--- a/phps-lexer.el
+++ b/phps-lexer.el
@@ -1278,6 +1278,26 @@ ANY_CHAR'
   (interactive)
   (setq phps-mode/lexer-tokens (semantic-lex-buffer)))
 
+(defun phps-mode/move-lexer-tokens (old-tokens start diff)
+  "Move lexer OLD-TOKENS positions after START with DIFF points."
+  (let ((new-tokens '()))
+    (when old-tokens
+
+      ;; Iterate over all tokens, add those that are to be left unchanged and
+      ;; add modified ones that are to be changed.
+      (catch 'stop-iteration
+        (dolist (token (nreverse old-tokens))
+          (let ((token-symbol (car token))
+                (token-start (car (cdr token)))
+                (token-end (cdr (cdr token))))
+            (if (> token-start start)
+                (let ((new-token-start (+ token-start diff))
+                      (new-token-end (+ token-end diff)))
+                  (push `(,token-symbol ,new-token-start ,new-token-end) 
new-tokens)
+                  (push token new-tokens))))))
+
+      new-tokens)))
+
 (defun phps-mode/run-incremental-lex ()
   "Run incremental lexer based on `phps-mode/buffer-changes--start'."
   (when (and (boundp 'phps-mode/buffer-changes--start)



reply via email to

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