aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKévin Le Gouguec2019-05-12 18:55:01 +0200
committerNoam Postavsky2019-05-13 20:41:02 -0400
commit417c52b0b7fbf5cb02d229e81b7aaaacf2082bde (patch)
tree6b3e93ae130bd9551e1cd1ef780962dac3fa3c8c
parent59ad303e8f3bb174ce326c76a9e7649f602120db (diff)
downloademacs-417c52b0b7fbf5cb02d229e81b7aaaacf2082bde.tar.gz
emacs-417c52b0b7fbf5cb02d229e81b7aaaacf2082bde.zip
Extract common code for adding text properties
* lisp/font-lock.el (font-lock--add-text-property): New function. (font-lock-prepend-text-property) (font-lock-append-text-property): Use it. (Bug#35476)
-rw-r--r--lisp/font-lock.el47
1 files changed, 20 insertions, 27 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 95ca2f99c21..3991a4ee8ef 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -1387,11 +1387,13 @@ delimit the region to fontify."
1387;; below and given a `font-lock-' prefix. Those that are not used are defined 1387;; below and given a `font-lock-' prefix. Those that are not used are defined
1388;; in Lisp below and commented out. sm. 1388;; in Lisp below and commented out. sm.
1389 1389
1390(defun font-lock-prepend-text-property (start end prop value &optional object) 1390(defun font-lock--add-text-property (start end prop value object append)
1391 "Prepend to one property of the text from START to END. 1391 "Add an element to a property of the text from START to END.
1392Arguments PROP and VALUE specify the property and value to prepend to the value 1392Arguments PROP and VALUE specify the property and value to add to
1393already in place. The resulting property values are always lists. 1393the value already in place. The resulting property values are
1394Optional argument OBJECT is the string or buffer containing the text." 1394always lists. Argument OBJECT is the string or buffer containing
1395the text. If argument APPEND is non-nil, VALUE will be appended,
1396otherwise it will be prepended."
1395 (let ((val (if (and (listp value) (not (keywordp (car value)))) 1397 (let ((val (if (and (listp value) (not (keywordp (car value))))
1396 ;; Already a list of faces. 1398 ;; Already a list of faces.
1397 value 1399 value
@@ -1407,35 +1409,26 @@ Optional argument OBJECT is the string or buffer containing the text."
1407 (or (keywordp (car prev)) 1409 (or (keywordp (car prev))
1408 (memq (car prev) '(foreground-color background-color))) 1410 (memq (car prev) '(foreground-color background-color)))
1409 (setq prev (list prev))) 1411 (setq prev (list prev)))
1410 (put-text-property start next prop 1412 (let* ((list-prev (if (listp prev) prev (list prev)))
1411 (append val (if (listp prev) prev (list prev))) 1413 (new-value (if append
1412 object) 1414 (append list-prev val)
1415 (append val list-prev))))
1416 (put-text-property start next prop new-value object))
1413 (setq start next)))) 1417 (setq start next))))
1414 1418
1419(defun font-lock-prepend-text-property (start end prop value &optional object)
1420 "Prepend to one property of the text from START to END.
1421Arguments PROP and VALUE specify the property and value to prepend to the value
1422already in place. The resulting property values are always lists.
1423Optional argument OBJECT is the string or buffer containing the text."
1424 (font-lock--add-text-property start end prop value object nil))
1425
1415(defun font-lock-append-text-property (start end prop value &optional object) 1426(defun font-lock-append-text-property (start end prop value &optional object)
1416 "Append to one property of the text from START to END. 1427 "Append to one property of the text from START to END.
1417Arguments PROP and VALUE specify the property and value to append to the value 1428Arguments PROP and VALUE specify the property and value to append to the value
1418already in place. The resulting property values are always lists. 1429already in place. The resulting property values are always lists.
1419Optional argument OBJECT is the string or buffer containing the text." 1430Optional argument OBJECT is the string or buffer containing the text."
1420 (let ((val (if (and (listp value) (not (keywordp (car value)))) 1431 (font-lock--add-text-property start end prop value object t))
1421 ;; Already a list of faces.
1422 value
1423 ;; A single face (e.g. a plist of face properties).
1424 (list value)))
1425 next prev)
1426 (while (/= start end)
1427 (setq next (next-single-property-change start prop object end)
1428 prev (get-text-property start prop object))
1429 ;; Canonicalize old forms of face property.
1430 (and (memq prop '(face font-lock-face))
1431 (listp prev)
1432 (or (keywordp (car prev))
1433 (memq (car prev) '(foreground-color background-color)))
1434 (setq prev (list prev)))
1435 (put-text-property start next prop
1436 (append (if (listp prev) prev (list prev)) val)
1437 object)
1438 (setq start next))))
1439 1432
1440(defun font-lock-fillin-text-property (start end prop value &optional object) 1433(defun font-lock-fillin-text-property (start end prop value &optional object)
1441 "Fill in one property of the text from START to END. 1434 "Fill in one property of the text from START to END.