diff options
author | Alan Mackenzie <acm@muc.de> | 2018-07-01 11:39:03 +0000 |
---|---|---|
committer | Alan Mackenzie <acm@muc.de> | 2018-07-01 11:39:03 +0000 |
commit | 4a9b24e1780c980d033b44f3c86133bbab691ebe (patch) | |
tree | 400c23dcd89d63c01c9f4a39c330efb90bf93951 /lisp/font-lock.el | |
parent | 76eda952b09db6d79342b7ddfcae45c7c836ab62 (diff) | |
download | emacs-scratch/fontify-open-string.tar.gz |
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/font-lock.el')
-rw-r--r-- | lisp/font-lock.el | 24 |
1 files changed, 23 insertions, 1 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." (integer :tag "size")) :group 'font-lock :version "24.1") + +(defcustom font-lock-warn-open-string t + "Fontify the opening quote of an unterminated string with warning face? +This is done when this variable is non-nil. + +This works only when the syntax-table entry for newline contains the flag `s' +\(see page \"xxx\" in the Elisp manual)." + :type 'boolean + :group 'font-lock + :version "27.1") ;; Originally these variable values were face names such as `bold' etc. @@ -1597,18 +1607,30 @@ START should be at the beginning of a line." (replace-regexp-in-string "^ *" "" comment-end)))) ;; Find the `start' state. (state (syntax-ppss start)) - face beg) + face beg in-string s-c-start) (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) ;; ;; Find each interesting place between here and `end'. (while (progn (when (or (nth 3 state) (nth 4 state)) + (setq s-c-start (nth 8 state)) + (setq in-string (nth 3 state)) (setq face (funcall font-lock-syntactic-face-function state)) (setq beg (max (nth 8 state) start)) (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table)) (when face (put-text-property beg (point) 'face face)) +;;;; NEW STOUGH, 2018-06-29 + (put-text-property s-c-start (1+ s-c-start) + 'face + (if (and font-lock-warn-open-string + in-string + (not (nth 3 state)) + (not (eq in-string (char-before)))) + 'font-lock-warning-face + face)) +;;;; END OF NEW STOUGH (when (and (eq face 'font-lock-comment-face) (or font-lock-comment-start-skip comment-start-skip)) |