|
39 | 39 | (defvar SYNTOK-PARAMS-START-LIST "SYNTOK-PARAMS-START-LIST")
|
40 | 40 | (defvar SYNTOK-ASSIGN-SEMICOLON-CLOSER "SYNTOK-ASSIGN-SEMICOLON-CLOSER")
|
41 | 41 | (defvar SYNTOK-SPACING "SYNTOK-SPACING")
|
| 42 | +(defvar SYNTOK-STRING "SYNTOK-STRING") |
42 | 43 |
|
43 | 44 | ;; token search functions
|
44 | 45 |
|
|
54 | 55 | ;; modify the default forward token function such that it returns a token even for
|
55 | 56 | ;; parenthesis characters "(" ")"
|
56 | 57 | (progn
|
57 |
| - (let ((start-pnt (point))) |
58 |
| - ;; return the whole string as a token |
59 |
| - ;; when inside a comment the `forward-comment' returns always `nil', moreover the strings |
60 |
| - ;; shall be given or a string the |
61 |
| - (forward-comment (point-max)) |
62 |
| - |
63 |
| - (if (> (point) start-pnt) |
64 |
| - ;; we just skipped a space-comments group, hence the general inter-token is returned, the |
65 |
| - ;; caller of this function will refine the search |
66 |
| - SYNTOK-SPACING |
67 |
| - (buffer-substring-no-properties |
68 |
| - (point) |
69 |
| - (cond |
70 |
| - ((and (zerop (skip-syntax-forward ".")) |
71 |
| - (zerop (skip-syntax-forward "(")) |
72 |
| - (zerop (skip-syntax-forward ")"))))) |
73 |
| - (progn (if |
74 |
| - (skip-syntax-forward "w_'")) |
75 |
| - (point))))))) |
| 58 | + (let* ((start-pnt (point)) |
| 59 | + (syntax-state (syntax-ppss start-pnt)) |
| 60 | + ;; do not try to get the state of the incremented point when at the end of the buffer |
| 61 | + (syntax-state-next (if (not (eobp)) |
| 62 | + (save-excursion |
| 63 | + (syntax-ppss (1+ start-pnt))) |
| 64 | + (syntax-class)))) ; it is expected a list so recycle the previous one |
| 65 | + |
| 66 | + (cond |
| 67 | + ;; the token search must stop when reaching the end of the buffer |
| 68 | + ((eobp) nil) |
| 69 | + |
| 70 | + ;; when inside a comment the `forward-comment' returns always `nil', hence use the syntax |
| 71 | + ;; state to skip it |
| 72 | + ((nth 4 syntax-state) |
| 73 | + (goto-char (nth 8 syntax-state)) ; to the comment start to easily skip it |
| 74 | + ;; move forward skipping comments and with characters |
| 75 | + (forward-comment (point-max)) |
| 76 | + SYNTOK-SPACING) |
| 77 | + |
| 78 | + ;; FIXME: the string case fails to leave a string context when the current string contains |
| 79 | + ;; the escaped apexes. |
| 80 | + |
| 81 | + ;; When inside of a string or just before a string opener character, a string-token shall be |
| 82 | + ;; returned. |
| 83 | + ((or (nth 3 syntax-state) (nth 3 syntax-state-next)) |
| 84 | + ;; skip all the characters inside the string (^ negate the class to be skipped) |
| 85 | + (skip-syntax-forward "\"") ; move inside the string when placed just before its opener |
| 86 | + (skip-syntax-forward "^\"") ; reach the string closer |
| 87 | + (skip-syntax-forward "\"") ; move after the string closer |
| 88 | + SYNTOK-STRING) |
| 89 | + |
| 90 | + ;; as not inside a comment or string search the next token based on the syntax class (after |
| 91 | + ;; skipping comments and white spaces) |
| 92 | + (t |
| 93 | + (forward-comment (point-max)) |
| 94 | + |
| 95 | + (if (> (point) start-pnt) |
| 96 | + ;; we just skipped a space-comments group, hence the general inter-token is returned, the |
| 97 | + ;; caller of this function will refine the search |
| 98 | + SYNTOK-SPACING |
| 99 | + (buffer-substring-no-properties |
| 100 | + (point) |
| 101 | + (cond |
| 102 | + ((and (zerop (skip-syntax-forward ".")) |
| 103 | + (zerop (skip-syntax-forward "(")) |
| 104 | + (zerop (skip-syntax-forward ")"))) |
| 105 | + (skip-syntax-forward "w_'") |
| 106 | + (point)) |
| 107 | + (t (point))) |
| 108 | + ))))))) |
76 | 109 | (defun sysver-basic-backward-token ()
|
77 | 110 | "Default backward search token function based on the syntax classes."
|
78 | 111 |
|
|
0 commit comments