|
61 | 61 | (syntax-state-next (if (not (eobp))
|
62 | 62 | (save-excursion
|
63 | 63 | (syntax-ppss (1+ start-pnt)))
|
64 |
| - (syntax-class)))) ; it is expected a list so recycle the previous one |
| 64 | + syntax-state))) ; it is expected a list so recycle the previous one |
65 | 65 |
|
66 | 66 | (cond
|
67 | 67 | ;; the token search must stop when reaching the end of the buffer
|
|
71 | 71 | ;; state to skip it
|
72 | 72 | ((nth 4 syntax-state)
|
73 | 73 | (goto-char (nth 8 syntax-state)) ; to the comment start to easily skip it
|
74 |
| - ;; move forward skipping comments and with characters |
| 74 | + ;; move forward skipping comments and space characters |
75 | 75 | (forward-comment (point-max))
|
76 | 76 | SYNTOK-SPACING)
|
77 | 77 |
|
|
93 | 93 | (forward-comment (point-max))
|
94 | 94 |
|
95 | 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 |
| 96 | + ;; we just skipped a space-comments group, hence the spacing-token is returned, the caller of this |
| 97 | + ;; function will refine the search |
98 | 98 | SYNTOK-SPACING
|
99 | 99 | (buffer-substring-no-properties
|
100 | 100 | (point)
|
|
104 | 104 | (zerop (skip-syntax-forward ")")))
|
105 | 105 | (skip-syntax-forward "w_'")
|
106 | 106 | (point))
|
107 |
| - (t (point))) |
108 |
| - ))))))) |
| 107 | + (t (point)))))))))) |
109 | 108 | (defun sysver-basic-backward-token ()
|
110 | 109 | "Default backward search token function based on the syntax classes."
|
111 | 110 |
|
112 | 111 | ;; NOTE: all explanations and comments are the same as for the `sysver-basic-forward-token'
|
113 | 112 | (progn
|
114 |
| - (let ((start-pnt (point))) |
115 |
| - (forward-comment (- (point))) |
116 |
| - |
117 |
| - (if (< (point) start-pnt) |
118 |
| - SYNTOK-SPACING |
119 |
| - (buffer-substring-no-properties |
120 |
| - (point) |
121 |
| - (progn (if (and (zerop (skip-syntax-backward ".")) |
122 |
| - (zerop (skip-syntax-backward "(")) |
123 |
| - (zerop (skip-syntax-backward ")"))) |
124 |
| - (skip-syntax-backward "w_'")) |
125 |
| - (point))))))) |
| 113 | + (let* ((start-pnt (point)) |
| 114 | + (syntax-state (syntax-ppss start-pnt)) |
| 115 | + (syntax-state-prev (if (not (bobp)) |
| 116 | + (save-excursion |
| 117 | + (syntax-ppss (1- start-pnt))) |
| 118 | + syntax-state))) |
| 119 | + |
| 120 | + (cond |
| 121 | + ;; the token search must stop when reaching the start of the buffer |
| 122 | + ((bobp) nil) |
| 123 | + |
| 124 | + ;; inside a comment |
| 125 | + ((nth 4 syntax-state) |
| 126 | + ;; move to the comment beginning as "forward-comment" does not work from inside it |
| 127 | + (goto-char (nth 8 syntax-state)) |
| 128 | + ;; move backward skipping comments and space characters |
| 129 | + (forward-comment (- (point))) |
| 130 | + SYNTOK-SPACING) |
| 131 | + |
| 132 | + ;; FIXME: the string case fails to leave a string context when the current string contains |
| 133 | + ;; the escaped apexes. |
| 134 | + |
| 135 | + ;; When inside of a string or just before a string opener character, a string-token shall be |
| 136 | + ;; returned. |
| 137 | + ((or (nth 3 syntax-state) (nth 3 syntax-state-prev)) |
| 138 | + ;; skip all the characters inside the string (^ negate the class to be skipped) |
| 139 | + (skip-syntax-backward "\"") ; move inside the string when placed just before its opener |
| 140 | + (skip-syntax-backward "^\"") ; reach the string closer |
| 141 | + (skip-syntax-backward "\"") ; move after the string closer |
| 142 | + SYNTOK-STRING) |
| 143 | + |
| 144 | + ;; elsewhere |
| 145 | + (t |
| 146 | + (forward-comment (- (point))) |
| 147 | + |
| 148 | + (if (< (point) start-pnt) |
| 149 | + SYNTOK-SPACING |
| 150 | + (buffer-substring-no-properties |
| 151 | + (point) |
| 152 | + (cond |
| 153 | + ((and (zerop (skip-syntax-backward ".")) |
| 154 | + (zerop (skip-syntax-backward "(")) |
| 155 | + (zerop (skip-syntax-backward ")"))) |
| 156 | + (skip-syntax-backward "w_'") |
| 157 | + (point)) |
| 158 | + (t (point)))))))))) |
126 | 159 |
|
127 | 160 | ;; Through the token search, the indentation can overcome the BNF grammar limits and
|
128 | 161 | ;; return "synthetic" tokens to ease the grammar definition.
|
|
0 commit comments