Commit 4a9b24e1 authored by Alan Mackenzie's avatar Alan Mackenzie

Initial commit. Allow wanted fontification of open string in any mode.

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

lisp/progmodes/sh-script.el (sh-mode-syntax-table): Add flag `s' to syntax
entry for \n.
parent 76eda952
Pipeline #27 failed with stage
......@@ -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'.
(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
(when face (put-text-property beg (point) 'face face))
;;;; NEW STOUGH, 2018-06-29
(put-text-property s-c-start (1+ s-c-start)
(if (and font-lock-warn-open-string
(not (nth 3 state))
(not (eq in-string (char-before))))
(when (and (eq face 'font-lock-comment-face)
(or font-lock-comment-start-skip
......@@ -429,7 +429,7 @@ name symbol."
(defvar sh-mode-syntax-table
(sh-mode-syntax-table ()
?\# "<"
?\n ">#"
?\n ">#s"
?\" "\"\""
?\' "\"'"
?\` "\"`"
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment