aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorStephen Leake2019-04-11 14:00:02 -0700
committerStephen Leake2019-04-11 14:00:02 -0700
commit7ba7def5caf7ec9d9bebffff489f0a658229fbda (patch)
treee0cfcb59937ca0528fb81769d7d48a904a91f5dc /lisp/progmodes/python.el
parent7768581172e11be52b1fcd8224f4594e126bbdb7 (diff)
parentde238b39e335c6814283faa171b35145f124edf2 (diff)
downloademacs-7ba7def5caf7ec9d9bebffff489f0a658229fbda.tar.gz
emacs-7ba7def5caf7ec9d9bebffff489f0a658229fbda.zip
Merge commit 'de238b39e335c6814283faa171b35145f124edf2'
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el40
1 files changed, 16 insertions, 24 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 5d0d03d5029..b05f9a33e90 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -675,7 +675,7 @@ Which one will be chosen depends on the value of
675 675
676(defconst python-syntax-propertize-function 676(defconst python-syntax-propertize-function
677 (syntax-propertize-rules 677 (syntax-propertize-rules
678 ((python-rx string-delimiter) 678 ((rx (or "\"\"\"" "'''"))
679 (0 (ignore (python-syntax-stringify)))))) 679 (0 (ignore (python-syntax-stringify))))))
680 680
681(define-obsolete-variable-alias 'python--prettify-symbols-alist 681(define-obsolete-variable-alias 'python--prettify-symbols-alist
@@ -701,35 +701,27 @@ is used to limit the scan."
701 701
702(defun python-syntax-stringify () 702(defun python-syntax-stringify ()
703 "Put `syntax-table' property correctly on single/triple quotes." 703 "Put `syntax-table' property correctly on single/triple quotes."
704 (let* ((num-quotes (length (match-string-no-properties 1))) 704 (let* ((ppss (save-excursion (backward-char 3) (syntax-ppss)))
705 (ppss (prog2 705 (string-start (and (eq t (nth 3 ppss)) (nth 8 ppss)))
706 (backward-char num-quotes) 706 (quote-starting-pos (- (point) 3))
707 (syntax-ppss) 707 (quote-ending-pos (point)))
708 (forward-char num-quotes))) 708 (cond ((or (nth 4 ppss) ;Inside a comment
709 (string-start (and (not (nth 4 ppss)) (nth 8 ppss))) 709 (and string-start
710 (quote-starting-pos (- (point) num-quotes)) 710 ;; Inside of a string quoted with different triple quotes.
711 (quote-ending-pos (point)) 711 (not (eql (char-after string-start)
712 (num-closing-quotes 712 (char-after quote-starting-pos)))))
713 (and string-start 713 ;; Do nothing.
714 (python-syntax-count-quotes
715 (char-before) string-start quote-starting-pos))))
716 (cond ((and string-start (= num-closing-quotes 0))
717 ;; This set of quotes doesn't match the string starting
718 ;; kind. Do nothing.
719 nil) 714 nil)
720 ((not string-start) 715 ((nth 5 ppss)
716 ;; The first quote is escaped, so it's not part of a triple quote!
717 (goto-char (1+ quote-starting-pos)))
718 ((null string-start)
721 ;; This set of quotes delimit the start of a string. 719 ;; This set of quotes delimit the start of a string.
722 (put-text-property quote-starting-pos (1+ quote-starting-pos) 720 (put-text-property quote-starting-pos (1+ quote-starting-pos)
723 'syntax-table (string-to-syntax "|"))) 721 'syntax-table (string-to-syntax "|")))
724 ((= num-quotes num-closing-quotes) 722 (t
725 ;; This set of quotes delimit the end of a string. 723 ;; This set of quotes delimit the end of a string.
726 (put-text-property (1- quote-ending-pos) quote-ending-pos 724 (put-text-property (1- quote-ending-pos) quote-ending-pos
727 'syntax-table (string-to-syntax "|")))
728 ((> num-quotes num-closing-quotes)
729 ;; This may only happen whenever a triple quote is closing
730 ;; a single quoted string. Add string delimiter syntax to
731 ;; all three quotes.
732 (put-text-property quote-starting-pos quote-ending-pos
733 'syntax-table (string-to-syntax "|")))))) 725 'syntax-table (string-to-syntax "|"))))))
734 726
735(defvar python-mode-syntax-table 727(defvar python-mode-syntax-table