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

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

[elpa] externals/phps-mode 6593242 257/405: Preparations for doing inden


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 6593242 257/405: Preparations for doing indentation and imenu in one pass
Date: Sat, 13 Jul 2019 10:00:27 -0400 (EDT)

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

    Preparations for doing indentation and imenu in one pass
---
 phps-mode-functions.el | 21 +++++++++++++++------
 phps-mode-lexer.el     |  5 +++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 90eb41a..a9a4900 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -37,6 +37,9 @@
 (defvar phps-mode-functions-imenu nil
   "The Imenu alist for current buffer, nil if none.")
 
+(defvar phps-mode-functions-processed-buffer nil
+  "Flag whether current buffer is processed or not.")
+
 (defvar phps-mode-functions-verbose nil
   "Verbose messaging, default nil.")
 
@@ -45,6 +48,15 @@
 
 ;; TODO Add support for automatic parenthesis, bracket, square-bracket, 
single-quote and double-quote encapsulations
 
+(defun phps-mode-functions-process-current-buffer ()
+  "Process current buffer, generate indentations and Imenu."
+  (unless phps-mode-functions-processed-buffer
+    (unless phps-mode-functions-lines-indent
+      (setq phps-mode-functions-lines-indent 
(phps-mode-functions-get-lines-indent)))
+    (unless phps-mode-functions-imenu
+      (setq phps-mode-functions-imenu 
(phps-mode-functions--imenu-create-index-function)))
+    (setq phps-mode-functions-processed-buffer t)))
+
 ;; Set indent for white-space lines as well
 (defun phps-mode-functions-get-lines-indent ()
   "Get the column and tuning indentation-numbers for each line in buffer that 
contain tokens."
@@ -528,10 +540,7 @@
 
 (defun phps-mode-functions-indent-line ()
   "Indent line."
-  ;; Set lines indent if not set
-  (unless phps-mode-functions-lines-indent
-    (setq phps-mode-functions-lines-indent 
(phps-mode-functions-get-lines-indent)))
-
+  (phps-mode-functions-process-current-buffer)
   (when phps-mode-functions-lines-indent
     (let ((indent (gethash (line-number-at-pos (point)) 
phps-mode-functions-lines-indent)))
       (when indent
@@ -689,8 +698,7 @@
 
 (defun phps-mode-functions-get-imenu ()
   "Get Imenu for current buffer."
-  (unless phps-mode-functions-imenu
-    (setq phps-mode-functions-imenu 
(phps-mode-functions--imenu-create-index-function)))
+  (phps-mode-functions-process-current-buffer)
   phps-mode-functions-imenu)
 
 (defun phps-mode-functions-init ()
@@ -716,6 +724,7 @@
   (set (make-local-variable 'phps-mode-functions-buffer-changes-start) nil)
   (set (make-local-variable 'phps-mode-functions-lines-indent) nil)
   (set (make-local-variable 'phps-mode-functions-imenu) nil)
+  (set (make-local-variable 'phps-mode-functions-processed-buffer) nil)
 
   (add-hook 'after-change-functions #'phps-mode-functions-after-change))
 
diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el
index 1e6b00f..a4dcc44 100644
--- a/phps-mode-lexer.el
+++ b/phps-mode-lexer.el
@@ -1270,6 +1270,11 @@ ANY_CHAR'
   "Just prepare other lexers for lexing region START to END."
   ;; (message "phps-mode-lexer-setup %s %s" start end)
 
+  ;; Flag that buffer has not been processed
+  (when (and (boundp 'phps-mode-functions-processed-buffer)
+             phps-mode-functions-processed-buffer)
+    (setq phps-mode-functions-processed-buffer nil))
+
   ;; Reset line indents
   (when (and (boundp 'phps-mode-functions-lines-indent)
              phps-mode-functions-lines-indent)



reply via email to

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