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

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

[elpa] externals/phps-mode bc5039e32f 086/212: Created custom determine


From: Christian Johansson
Subject: [elpa] externals/phps-mode bc5039e32f 086/212: Created custom determine string indentation function
Date: Wed, 26 Jan 2022 01:50:58 -0500 (EST)

branch: externals/phps-mode
commit bc5039e32f3ebd3adf4e7d5c6cbb36d9cfc97139
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Created custom determine string indentation function
---
 phps-mode-indent.el | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index c693027643..e6acb397b0 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -10,6 +10,23 @@
 ;;; Code:
 
 
+(defun phps-mode-indent--string-indentation (string)
+  "Count indentation of STRING."
+  (let ((occurences 0)
+        (start 0)
+        (length (length string)))
+    (when (< start length)
+      (let ((match-start (string-match "[\t ]" string start)))
+        (while (and
+                match-start
+                (= match-start start))
+          (setq occurences (1+ occurences))
+          (setq start (match-end 0))
+          (if (< start length)
+              (setq match-start (string-match "[\t ]" string start))
+            (setq match-start nil)))))
+    occurences))
+
 (defun phps-mode-indent-line (&optional initial-point)
   "Apply alternative indentation at INITIAL-POINT here."
   (let ((point))
@@ -56,11 +73,9 @@
             (setq
              move-length (1+ move-length)))
 
-          (message "Previous non-empty line: %S" line-string)
-
           (if line-is-empty-p
               (indent-line-to 0)
-            (let* ((old-indentation (current-indentation))
+            (let* ((old-indentation (phps-mode-indent--string-indentation 
line-string))
                    (current-line-starts-with-closing-bracket 
(phps-mode-indent--string-starts-with-closing-bracket-p current-line-string))
                    (line-starts-with-closing-bracket 
(phps-mode-indent--string-starts-with-closing-bracket-p line-string))
                    (line-starts-with-opening-doc-comment 
(phps-mode-indent--string-starts-with-opening-doc-comment-p line-string))
@@ -69,6 +84,8 @@
                    (line-ends-with-terminus 
(phps-mode-indent--string-ends-with-terminus-p line-string))
                    (bracket-level (phps-mode-indent--get-string-brackets-count 
line-string))
                    (line-ends-with-implements-p (string-match-p "[\t 
]+implements$" line-string)))
+              (message "Previous non-empty line: %S with indentation: %S" 
line-string old-indentation)
+
               (setq new-indentation old-indentation)
               (goto-char point)
 
@@ -148,6 +165,7 @@
               ;; Decrease indentation if current line decreases in bracket 
level
               (when (< new-indentation 0)
                 (setq new-indentation 0))
+              (message "new-indentation: %S bracket-level: %S old-indentation: 
%S" new-indentation bracket-level old-indentation)
 
               (indent-line-to new-indentation)))))
       ;; Only move to end of line if point is the current point and is at end 
of line



reply via email to

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