[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 0ca9fe8 058/405: Detection of point inside do
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 0ca9fe8 058/405: Detection of point inside doc comment block improved |
Date: |
Sat, 13 Jul 2019 09:59:42 -0400 (EDT) |
branch: externals/phps-mode
commit 0ca9fe8ed30c99a573976def04fc6458b38330ca
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Detection of point inside doc comment block improved
---
phps-functions.el | 39 +++++++++++++++++++++++++--------------
phps-test-functions.el | 12 ++++++++++--
2 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/phps-functions.el b/phps-functions.el
index 03b1119..497a0fd 100644
--- a/phps-functions.el
+++ b/phps-functions.el
@@ -55,11 +55,15 @@
(start-token-number (nth 4 start))
(end-bracket-level (nth 1 end))
(end-parenthesis-level (nth 2 end))
- (end-token-number (nth 4 end)))
+ (end-token-number (nth 4 end))
+ (in-doc-comment (nth 5 start)))
(let* ((indent-start (+ start-bracket-level start-parenthesis-level))
(indent-end (+ end-bracket-level end-parenthesis-level))
- (indent-level indent-start))
+ (indent-level indent-start)
+ (indent-adjust 0))
;; (message "indent-start %s, indent-end %s" indent-start
indent-end)
+
+ ;; When bracket count at start is larger than bracket count at end
(when (and
(boundp 'phps-mode/lexer-tokens)
(> indent-start indent-end))
@@ -87,17 +91,22 @@
(when valid-tokens
;; (message "Tokens was valid, decreasing indent %s - %s"
(line-beginning-position) (line-end-position))
(setq indent-level (- indent-level (- indent-start
indent-end))))))
- ;; (message "inside scripting, start: %s, end: %s, indenting to
column %s " start end indent-level)
- (indent-line-to (* indent-level tab-width))
- (phps-mode/run-incremental-lex)))))))
-;; TODO Implement this
+ (when in-doc-comment
+ (setq indent-adjust 1))
+
+ (let ((indent-sum (+ (* indent-level tab-width) indent-adjust)))
+ ;; (message "Indenting to %s" indent-sum)
+ ;; (message "inside scripting, start: %s, end: %s, indenting to
column %s " start end indent-level)
+ (indent-line-to indent-sum)
+ (phps-mode/run-incremental-lex))))))))
+
+;; TODO Implement this?
(defun phps-mode/indent-region ()
"Indent region."
)
-;; TODO This function should track between what min and max region a specific
buffer has been modified and then re-run lexer for that region when editor is
idle, maybe use (buffer-name))
-;; maybe use 'auto-save-hook for this
+;; TODO Fix flycheck error here
(defun phps-mode/after-change-functions (start stop length)
"Track buffer change from START to STOP with length LENGTH."
(when (string= major-mode "phps-mode")
@@ -117,7 +126,7 @@
(when (boundp 'phps-mode/lexer-tokens)
(save-excursion
(beginning-of-line)
- (let ((position (point))
+ (let ((line-beginning (point))
(line-end (line-end-position))
(start-in-scripting nil)
(start-brace-level 0)
@@ -143,12 +152,12 @@
(throw 'stop-iteration nil))
(when (and (not found-line-tokens)
- (>= token-start position)
+ (>= token-start line-beginning)
(<= token-end line-end))
(setq found-line-tokens t))
;; When end of token is equal or less to current point
- (when (<= token-end position)
+ (when (<= token-end line-beginning)
(when (null start-token-number)
(setq start-token-number -1))
(setq start-token-number (+ start-token-number 1))
@@ -156,24 +165,26 @@
('T_OPEN_TAG (setq start-in-scripting t))
('T_OPEN_TAG_WITH_ECHO (setq start-in-scripting t))
('T_CLOSE_TAG (setq start-in-scripting nil))
- ('T_DOC_COMMENT (setq line-in-doc-comment nil))
("}" (setq start-brace-level (- start-brace-level 1)))
("{" (setq start-brace-level (+ start-brace-level 1)))
("(" (setq start-parenthesis-level (+
start-parenthesis-level 1)))
(")" (setq start-parenthesis-level (-
start-parenthesis-level 1)))
(_)))
+ (when (and (> token-end line-end)
+ (< token-start line-beginning)
+ (eq token 'T_DOC_COMMENT))
+ (setq line-in-doc-comment t))
+
;; When start of token is equal or less to end of curent line
(when (<= token-start line-end)
(when (null end-token-number)
(setq end-token-number -1))
(setq end-token-number (+ end-token-number 1))
- (setq line-in-doc-comment nil)
(pcase token
('T_OPEN_TAG (setq end-in-scripting t))
('T_OPEN_TAG_WITH_ECHO (setq end-in-scripting t))
('T_CLOSE_TAG (setq end-in-scripting nil))
- ('T_DOC_COMMENT (setq line-in-doc-comment t))
("}" (setq end-brace-level (- end-brace-level 1)))
("{" (setq end-brace-level (+ end-brace-level 1)))
("(" (setq end-parenthesis-level (+ end-parenthesis-level
1)))
diff --git a/phps-test-functions.el b/phps-test-functions.el
index a79babb..d8fae17 100644
--- a/phps-test-functions.el
+++ b/phps-test-functions.el
@@ -100,6 +100,14 @@
(should (equal buffer-contents "<?php\n/**\n * My first line\n* My
second line\n**/\n"))))
(phps-mode/with-test-buffer
+ "<?php\n/**\n* My first line\n* My second line\n**/\n"
+ (goto-char 9)
+ (phps-mode/indent-line)
+ ;; (message "Tokens %s point %s" phps-mode/lexer-tokens (point))
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (should (equal buffer-contents "<?php\n/**\n* My first line\n* My second
line\n**/\n"))))
+
+ (phps-mode/with-test-buffer
"<?php\n$variable = array(\n'random4');\n$variable = true;\n"
(goto-char 29)
(phps-mode/indent-line)
@@ -170,8 +178,8 @@
(phps-mode/with-test-buffer
"<?php /**\n * My first line\n * My second line\n **/"
- (goto-char 10)
- (should (equal (list (list nil 0 0 0 nil t) (list t 0 0 0 1 t))
(phps-mode/get-point-data))))
+ (goto-char 9)
+ (should (equal (list (list nil 0 0 0 nil nil) (list t 0 0 0 1 nil))
(phps-mode/get-point-data))))
)
- [elpa] externals/phps-mode da1d1de 051/405: Temporary lexer after change until other work is ready, (continued)
- [elpa] externals/phps-mode da1d1de 051/405: Temporary lexer after change until other work is ready, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 990d3dd 054/405: Added test for indentation of multiple-line doc comment, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode dd80d27 055/405: Started work on detecting doc comment blocks, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e1b7160 053/405: (newline-and-indent) now working, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8aa1ab6 059/405: Another test for getting point data inside doc block, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 09daec3 052/405: Foundation for incremental lexer and syntax colorer completed, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3f4c344 056/405: Fixed detection of doc comment blocks, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3824abf 060/405: Resolved indent with trailing parenthesis, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a61cb8b 062/405: Fixed issue with doc comment indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 6c597fb 065/405: Updated readme, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0ca9fe8 058/405: Detection of point inside doc comment block improved,
Stefan Monnier <=
- [elpa] externals/phps-mode 67f9a7a 057/405: Moved lexer-get-point-data to functions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 27cd705 069/405: Updated readme, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 58300fd 070/405: More updates of readme, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 86ec35f 066/405: Incremental lexer working somewhat, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode ec71e15 074/405: Fixed bug where token-numbers are not defined, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 236f05e 071/405: Updated makefile to not use hard-coded path to emacs, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode bf633d2 061/405: Added test for indent of final line of doc comment block, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode ba8165a 063/405: Fixed bug with brace count not including braces inside double quoted strings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 99dfc68 067/405: Incremental-lexer deletes affected overlays, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 90d059c 064/405: Fixed bug in incremental lexer logic, Stefan Monnier, 2019/07/13