diff options
| author | Alan Mackenzie | 2018-07-01 11:39:03 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2018-07-01 11:39:03 +0000 |
| commit | 4a9b24e1780c980d033b44f3c86133bbab691ebe (patch) | |
| tree | 400c23dcd89d63c01c9f4a39c330efb90bf93951 /lisp | |
| parent | 76eda952b09db6d79342b7ddfcae45c7c836ab62 (diff) | |
| download | emacs-scratch/fontify-open-string.tar.gz emacs-scratch/fontify-open-string.zip | |
Initial commit. Allow wanted fontification of open string in any mode.scratch/fontify-open-string
The wanted fontification is for the string face to end at the first unescaped
newline. This is achieved by a new syntax flag `s' on NL, which means
"terminate any open string".
src/syntax.c (SYNTAX_FLAGS_CLOSE_STRING, back_maybe_string): New functions.
(Fstring_to_syntax, Finternal_describe_syntax_value, scan_lists)
(scan_sexps_forward): Adapt to handle the `s' flag.
lisp/font-lock.el (font-lock-warn-open-string): New defcustom.
(font-lock-fontify-syntactically-region): Enhance to fontify " with
warning-face.
lisp/progmodes/sh-script.el (sh-mode-syntax-table): Add flag `s' to syntax
entry for \n.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/font-lock.el | 24 | ||||
| -rw-r--r-- | lisp/progmodes/sh-script.el | 2 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el index be9fb4dc93f..f2b7fef5c23 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el | |||
| @@ -287,6 +287,16 @@ If a number, only buffers greater than this size have fontification messages." | |||
| 287 | (integer :tag "size")) | 287 | (integer :tag "size")) |
| 288 | :group 'font-lock | 288 | :group 'font-lock |
| 289 | :version "24.1") | 289 | :version "24.1") |
| 290 | |||
| 291 | (defcustom font-lock-warn-open-string t | ||
| 292 | "Fontify the opening quote of an unterminated string with warning face? | ||
| 293 | This is done when this variable is non-nil. | ||
| 294 | |||
| 295 | This works only when the syntax-table entry for newline contains the flag `s' | ||
| 296 | \(see page \"xxx\" in the Elisp manual)." | ||
| 297 | :type 'boolean | ||
| 298 | :group 'font-lock | ||
| 299 | :version "27.1") | ||
| 290 | 300 | ||
| 291 | 301 | ||
| 292 | ;; Originally these variable values were face names such as `bold' etc. | 302 | ;; Originally these variable values were face names such as `bold' etc. |
| @@ -1597,18 +1607,30 @@ START should be at the beginning of a line." | |||
| 1597 | (replace-regexp-in-string "^ *" "" comment-end)))) | 1607 | (replace-regexp-in-string "^ *" "" comment-end)))) |
| 1598 | ;; Find the `start' state. | 1608 | ;; Find the `start' state. |
| 1599 | (state (syntax-ppss start)) | 1609 | (state (syntax-ppss start)) |
| 1600 | face beg) | 1610 | face beg in-string s-c-start) |
| 1601 | (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) | 1611 | (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) |
| 1602 | ;; | 1612 | ;; |
| 1603 | ;; Find each interesting place between here and `end'. | 1613 | ;; Find each interesting place between here and `end'. |
| 1604 | (while | 1614 | (while |
| 1605 | (progn | 1615 | (progn |
| 1606 | (when (or (nth 3 state) (nth 4 state)) | 1616 | (when (or (nth 3 state) (nth 4 state)) |
| 1617 | (setq s-c-start (nth 8 state)) | ||
| 1618 | (setq in-string (nth 3 state)) | ||
| 1607 | (setq face (funcall font-lock-syntactic-face-function state)) | 1619 | (setq face (funcall font-lock-syntactic-face-function state)) |
| 1608 | (setq beg (max (nth 8 state) start)) | 1620 | (setq beg (max (nth 8 state) start)) |
| 1609 | (setq state (parse-partial-sexp (point) end nil nil state | 1621 | (setq state (parse-partial-sexp (point) end nil nil state |
| 1610 | 'syntax-table)) | 1622 | 'syntax-table)) |
| 1611 | (when face (put-text-property beg (point) 'face face)) | 1623 | (when face (put-text-property beg (point) 'face face)) |
| 1624 | ;;;; NEW STOUGH, 2018-06-29 | ||
| 1625 | (put-text-property s-c-start (1+ s-c-start) | ||
| 1626 | 'face | ||
| 1627 | (if (and font-lock-warn-open-string | ||
| 1628 | in-string | ||
| 1629 | (not (nth 3 state)) | ||
| 1630 | (not (eq in-string (char-before)))) | ||
| 1631 | 'font-lock-warning-face | ||
| 1632 | face)) | ||
| 1633 | ;;;; END OF NEW STOUGH | ||
| 1612 | (when (and (eq face 'font-lock-comment-face) | 1634 | (when (and (eq face 'font-lock-comment-face) |
| 1613 | (or font-lock-comment-start-skip | 1635 | (or font-lock-comment-start-skip |
| 1614 | comment-start-skip)) | 1636 | comment-start-skip)) |
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el index aaa86b5816f..bf760e0a6cc 100644 --- a/lisp/progmodes/sh-script.el +++ b/lisp/progmodes/sh-script.el | |||
| @@ -429,7 +429,7 @@ name symbol." | |||
| 429 | (defvar sh-mode-syntax-table | 429 | (defvar sh-mode-syntax-table |
| 430 | (sh-mode-syntax-table () | 430 | (sh-mode-syntax-table () |
| 431 | ?\# "<" | 431 | ?\# "<" |
| 432 | ?\n ">#" | 432 | ?\n ">#s" |
| 433 | ?\" "\"\"" | 433 | ?\" "\"\"" |
| 434 | ?\' "\"'" | 434 | ?\' "\"'" |
| 435 | ?\` "\"`" | 435 | ?\` "\"`" |