diff options
| author | Stefan Monnier | 2024-04-01 02:12:51 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2024-04-01 02:14:13 -0400 |
| commit | 0f504dde3388687d1214182fa519354146947635 (patch) | |
| tree | 0a8272d039c56d968a6acf97b10f37f8ba1c794e | |
| parent | 9caf5cb55a3889fea019c73d6a3040204d77bf39 (diff) | |
| download | emacs-0f504dde3388687d1214182fa519354146947635.tar.gz emacs-0f504dde3388687d1214182fa519354146947635.zip | |
(scheme-syntax-propertize-sexp-comment): Handle nested sexp-comments
Well, I'm not completely sure this will work right in all cases,
because I've been confused about this in the past.
It works in my test case, at least.
* lisp/progmodes/scheme.el (scheme-syntax-propertize-sexp-comment):
Look for nested `#;` and mark them appropriately.
| -rw-r--r-- | etc/NEWS | 1 | ||||
| -rw-r--r-- | lisp/progmodes/scheme.el | 43 |
2 files changed, 34 insertions, 10 deletions
| @@ -1222,6 +1222,7 @@ interactive Python interpreter specified by 'python-interpreter'. | |||
| 1222 | 1222 | ||
| 1223 | Scheme mode now handles regular expression literal #/regexp/ that is | 1223 | Scheme mode now handles regular expression literal #/regexp/ that is |
| 1224 | available in some Scheme implementations. | 1224 | available in some Scheme implementations. |
| 1225 | Also, it should now handle nested sexp-comments. | ||
| 1225 | 1226 | ||
| 1226 | ** use-package | 1227 | ** use-package |
| 1227 | 1228 | ||
diff --git a/lisp/progmodes/scheme.el b/lisp/progmodes/scheme.el index 8652abeb817..79d076ff145 100644 --- a/lisp/progmodes/scheme.el +++ b/lisp/progmodes/scheme.el | |||
| @@ -50,6 +50,7 @@ | |||
| 50 | ;;; Code: | 50 | ;;; Code: |
| 51 | 51 | ||
| 52 | (require 'lisp-mode) | 52 | (require 'lisp-mode) |
| 53 | (eval-when-compile 'subr-x) ;For `named-let'. | ||
| 53 | 54 | ||
| 54 | (defvar scheme-mode-syntax-table | 55 | (defvar scheme-mode-syntax-table |
| 55 | (let ((st (make-syntax-table)) | 56 | (let ((st (make-syntax-table)) |
| @@ -426,18 +427,40 @@ See `run-hooks'." | |||
| 426 | (point) end)) | 427 | (point) end)) |
| 427 | 428 | ||
| 428 | (defun scheme-syntax-propertize-sexp-comment (end) | 429 | (defun scheme-syntax-propertize-sexp-comment (end) |
| 429 | (let ((state (syntax-ppss))) | 430 | (let ((state (syntax-ppss)) |
| 431 | (checked (point))) | ||
| 430 | (when (eq 2 (nth 7 state)) | 432 | (when (eq 2 (nth 7 state)) |
| 431 | ;; It's a sexp-comment. Tell parse-partial-sexp where it ends. | 433 | ;; It's a sexp-comment. Tell parse-partial-sexp where it ends. |
| 432 | (condition-case nil | 434 | (named-let loop ((startpos (+ 2 (nth 8 state)))) |
| 433 | (progn | 435 | (let ((found nil)) |
| 434 | (goto-char (+ 2 (nth 8 state))) | 436 | (while |
| 435 | ;; FIXME: this doesn't handle the case where the sexp | 437 | (progn |
| 436 | ;; itself contains a #; comment. | 438 | (setq found nil) |
| 437 | (forward-sexp 1) | 439 | (condition-case nil |
| 438 | (put-text-property (1- (point)) (point) | 440 | (progn |
| 439 | 'syntax-table (string-to-syntax "> cn"))) | 441 | (goto-char startpos) |
| 440 | (scan-error (goto-char end)))))) | 442 | (forward-sexp 1) |
| 443 | (setq found (point))) | ||
| 444 | (scan-error (goto-char end))) | ||
| 445 | ;; If there's a nested `#;', the syntax-tables will normally | ||
| 446 | ;; consider the `;' to start a normal comment, so the | ||
| 447 | ;; (forward-sexp 1) above may have landed at the wrong place. | ||
| 448 | ;; So look for `#;' in the text over which we jumped, and | ||
| 449 | ;; mark those we found as nested sexp-comments. | ||
| 450 | (let ((limit (or found end))) | ||
| 451 | (when (< checked limit) | ||
| 452 | (goto-char checked) | ||
| 453 | (when (re-search-forward "\\(#\\);" limit 'move) | ||
| 454 | (setq checked (point)) | ||
| 455 | (put-text-property (match-beginning 1) (match-end 1) | ||
| 456 | 'syntax-table | ||
| 457 | (string-to-syntax "< cn")) | ||
| 458 | (loop (point))) | ||
| 459 | (< (point) limit))))) | ||
| 460 | (when found | ||
| 461 | (goto-char found) | ||
| 462 | (put-text-property (1- found) found | ||
| 463 | 'syntax-table (string-to-syntax "> cn")))))))) | ||
| 441 | 464 | ||
| 442 | (defun scheme-syntax-propertize-regexp (end) | 465 | (defun scheme-syntax-propertize-regexp (end) |
| 443 | (let* ((state (syntax-ppss)) | 466 | (let* ((state (syntax-ppss)) |