mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-28 07:45:00 +00:00
* lisp/progmodes/ruby-mode.el: Improve percent literals.
(ruby-percent-literal-beg-re): New constant. (ruby-syntax-general-delimiters-goto-beg): Rename to `ruby-syntax-enclosing-percent-literal', improve literal type check. (ruby-syntax-propertize-general-delimiters): Rename to `ruby-syntax-propertize-percent-literal', it's a shorter and more popular term. Adjust comments everywhere. (ruby-syntax-propertize-percent-literal): Only propertize when not inside a simple string or comment. When the literal is unclosed, leave the text after it unpropertized. Fixes: debbugs:6286
This commit is contained in:
parent
8e99d072be
commit
e636fafe20
@ -1,3 +1,16 @@
|
|||||||
|
2012-08-14 Dmitry Gutov <dgutov@yandex.ru>
|
||||||
|
|
||||||
|
* progmodes/ruby-mode.el: Improve percent literals (bug#6286).
|
||||||
|
(ruby-percent-literal-beg-re): New constant.
|
||||||
|
(ruby-syntax-general-delimiters-goto-beg): Rename to
|
||||||
|
`ruby-syntax-enclosing-percent-literal', improve literal type check.
|
||||||
|
(ruby-syntax-propertize-general-delimiters): Rename to
|
||||||
|
`ruby-syntax-propertize-percent-literal', it's a shorter and more
|
||||||
|
popular term. Adjust comments everywhere.
|
||||||
|
(ruby-syntax-propertize-percent-literal): Only propertize when not
|
||||||
|
inside a simple string or comment. When the literal is unclosed,
|
||||||
|
leave the text after it unpropertized.
|
||||||
|
|
||||||
2012-08-14 Andreas Schwab <schwab@linux-m68k.org>
|
2012-08-14 Andreas Schwab <schwab@linux-m68k.org>
|
||||||
|
|
||||||
* emacs-lisp/bytecomp.el (byte-recompile-file): When LOAD is
|
* emacs-lisp/bytecomp.el (byte-recompile-file): When LOAD is
|
||||||
@ -22,8 +35,8 @@
|
|||||||
Use `completion-table-dynamic' for completion functions.
|
Use `completion-table-dynamic' for completion functions.
|
||||||
* progmodes/python.el
|
* progmodes/python.el
|
||||||
(python-shell-completion--do-completion-at-point)
|
(python-shell-completion--do-completion-at-point)
|
||||||
(python-shell-completion--get-completions): Remove
|
(python-shell-completion--get-completions):
|
||||||
functions.
|
Remove functions.
|
||||||
(python-shell-completion-complete-at-point): New function.
|
(python-shell-completion-complete-at-point): New function.
|
||||||
(python-completion-complete-at-point): Use it.
|
(python-completion-complete-at-point): Use it.
|
||||||
|
|
||||||
|
@ -800,7 +800,7 @@ and `\\' when preceded by `?'."
|
|||||||
;; (not (or (eolp) (looking-at "#")
|
;; (not (or (eolp) (looking-at "#")
|
||||||
;; (and (eq (car (nth 1 state)) ?{)
|
;; (and (eq (car (nth 1 state)) ?{)
|
||||||
;; (looking-at "|"))))))
|
;; (looking-at "|"))))))
|
||||||
;; Not a regexp or general delimited literal.
|
;; Not a regexp or percent literal.
|
||||||
(null (nth 0 (ruby-parse-region (or begin parse-start)
|
(null (nth 0 (ruby-parse-region (or begin parse-start)
|
||||||
(point))))
|
(point))))
|
||||||
(or (not (eq ?| (char-after (point))))
|
(or (not (eq ?| (char-after (point))))
|
||||||
@ -1169,17 +1169,22 @@ See `add-log-current-defun-function'."
|
|||||||
(ruby-do-end-to-brace)))
|
(ruby-do-end-to-brace)))
|
||||||
|
|
||||||
(declare-function ruby-syntax-propertize-heredoc "ruby-mode" (limit))
|
(declare-function ruby-syntax-propertize-heredoc "ruby-mode" (limit))
|
||||||
(declare-function ruby-syntax-general-delimiters-goto-beg "ruby-mode" ())
|
(declare-function ruby-syntax-enclosing-percent-literal "ruby-mode" (limit))
|
||||||
(declare-function ruby-syntax-propertize-general-delimiters "ruby-mode" (limit))
|
(declare-function ruby-syntax-propertize-percent-literal "ruby-mode" (limit))
|
||||||
|
|
||||||
(if (eval-when-compile (fboundp #'syntax-propertize-rules))
|
(if (eval-when-compile (fboundp #'syntax-propertize-rules))
|
||||||
;; New code that works independently from font-lock.
|
;; New code that works independently from font-lock.
|
||||||
(progn
|
(progn
|
||||||
|
(eval-and-compile
|
||||||
|
(defconst ruby-percent-literal-beg-re
|
||||||
|
"\\(%\\)[qQrswWx]?\\([[:punct:]]\\)"
|
||||||
|
"Regexp to match the beginning of percent literal."))
|
||||||
|
|
||||||
(defun ruby-syntax-propertize-function (start end)
|
(defun ruby-syntax-propertize-function (start end)
|
||||||
"Syntactic keywords for Ruby mode. See `syntax-propertize-function'."
|
"Syntactic keywords for Ruby mode. See `syntax-propertize-function'."
|
||||||
(goto-char start)
|
(goto-char start)
|
||||||
(ruby-syntax-propertize-heredoc end)
|
(ruby-syntax-propertize-heredoc end)
|
||||||
(ruby-syntax-general-delimiters-goto-beg)
|
(ruby-syntax-enclosing-percent-literal end)
|
||||||
(funcall
|
(funcall
|
||||||
(syntax-propertize-rules
|
(syntax-propertize-rules
|
||||||
;; #{ }, #$hoge, #@foo are not comments.
|
;; #{ }, #$hoge, #@foo are not comments.
|
||||||
@ -1222,8 +1227,8 @@ See `add-log-current-defun-function'."
|
|||||||
'syntax-table (string-to-syntax "\""))
|
'syntax-table (string-to-syntax "\""))
|
||||||
(ruby-syntax-propertize-heredoc end))))
|
(ruby-syntax-propertize-heredoc end))))
|
||||||
;; Handle percent literals: %w(), %q{}, etc.
|
;; Handle percent literals: %w(), %q{}, etc.
|
||||||
("\\(?:^\\|[[ \t\n<+(,=]\\)\\(%\\)[qQrswWx]?\\([[:punct:]]\\)"
|
((concat "\\(?:^\\|[[ \t\n<+(,=]\\)" ruby-percent-literal-beg-re)
|
||||||
(1 (prog1 "|" (ruby-syntax-propertize-general-delimiters end)))))
|
(1 (prog1 "|" (ruby-syntax-propertize-percent-literal end)))))
|
||||||
(point) end))
|
(point) end))
|
||||||
|
|
||||||
(defun ruby-syntax-propertize-heredoc (limit)
|
(defun ruby-syntax-propertize-heredoc (limit)
|
||||||
@ -1251,40 +1256,46 @@ See `add-log-current-defun-function'."
|
|||||||
;; inf-loop.
|
;; inf-loop.
|
||||||
(if (< (point) start) (goto-char start))))))
|
(if (< (point) start) (goto-char start))))))
|
||||||
|
|
||||||
(defun ruby-syntax-general-delimiters-goto-beg ()
|
(defun ruby-syntax-enclosing-percent-literal (limit)
|
||||||
(let ((state (syntax-ppss)))
|
(let ((state (syntax-ppss))
|
||||||
;; Move to the start of the literal, in case it's multiline.
|
(start (point)))
|
||||||
;; TODO: determine the literal type more reliably here?
|
;; When already inside percent literal, re-propertize it.
|
||||||
(when (eq t (nth 3 state))
|
(when (eq t (nth 3 state))
|
||||||
(goto-char (nth 8 state))
|
(goto-char (nth 8 state))
|
||||||
(beginning-of-line))))
|
(when (looking-at ruby-percent-literal-beg-re)
|
||||||
|
(ruby-syntax-propertize-percent-literal limit))
|
||||||
|
(when (< (point) start) (goto-char start)))))
|
||||||
|
|
||||||
(defun ruby-syntax-propertize-general-delimiters (limit)
|
(defun ruby-syntax-propertize-percent-literal (limit)
|
||||||
(goto-char (match-beginning 2))
|
(goto-char (match-beginning 2))
|
||||||
(let* ((op (char-after))
|
;; Not inside a simple string or comment.
|
||||||
(ops (char-to-string op))
|
(when (eq t (nth 3 (syntax-ppss)))
|
||||||
(cl (or (cdr (aref (syntax-table) op))
|
(let* ((op (char-after))
|
||||||
(cdr (assoc op '((?< . ?>))))))
|
(ops (char-to-string op))
|
||||||
parse-sexp-lookup-properties)
|
(cl (or (cdr (aref (syntax-table) op))
|
||||||
(ignore-errors
|
(cdr (assoc op '((?< . ?>))))))
|
||||||
(if cl
|
parse-sexp-lookup-properties)
|
||||||
(progn ; Paired delimiters.
|
(condition-case nil
|
||||||
;; Delimiter pairs of the same kind can be nested
|
(progn
|
||||||
;; inside the literal, as long as they are balanced.
|
(if cl ; Paired delimiters.
|
||||||
;; Create syntax table that ignores other characters.
|
;; Delimiter pairs of the same kind can be nested
|
||||||
(with-syntax-table (make-char-table 'syntax-table nil)
|
;; inside the literal, as long as they are balanced.
|
||||||
(modify-syntax-entry op (concat "(" (char-to-string cl)))
|
;; Create syntax table that ignores other characters.
|
||||||
(modify-syntax-entry cl (concat ")" ops))
|
(with-syntax-table (make-char-table 'syntax-table nil)
|
||||||
(modify-syntax-entry ?\\ "\\")
|
(modify-syntax-entry op (concat "(" (char-to-string cl)))
|
||||||
(save-restriction
|
(modify-syntax-entry cl (concat ")" ops))
|
||||||
(narrow-to-region (point) limit)
|
(modify-syntax-entry ?\\ "\\")
|
||||||
(forward-list)))) ; skip to the paired character
|
(save-restriction
|
||||||
;; Single character delimiter.
|
(narrow-to-region (point) limit)
|
||||||
(re-search-forward (concat "[^\\]\\(?:\\\\\\\\\\)*"
|
(forward-list))) ; skip to the paired character
|
||||||
(regexp-quote ops)) limit nil))
|
;; Single character delimiter.
|
||||||
;; If we reached here, the closing delimiter was found.
|
(re-search-forward (concat "[^\\]\\(?:\\\\\\\\\\)*"
|
||||||
(put-text-property (1- (point)) (point)
|
(regexp-quote ops)) limit nil))
|
||||||
'syntax-table (string-to-syntax "|")))))
|
;; Found the closing delimiter.
|
||||||
|
(put-text-property (1- (point)) (point) 'syntax-table
|
||||||
|
(string-to-syntax "|")))
|
||||||
|
;; Unclosed literal, leave the following text unpropertized.
|
||||||
|
((scan-error search-failed) (goto-char limit))))))
|
||||||
)
|
)
|
||||||
|
|
||||||
;; For Emacsen where syntax-propertize-rules is not (yet) available,
|
;; For Emacsen where syntax-propertize-rules is not (yet) available,
|
||||||
@ -1329,7 +1340,7 @@ This should only be called after matching against `ruby-here-doc-end-re'."
|
|||||||
(4 (7 . ?/))
|
(4 (7 . ?/))
|
||||||
(6 (7 . ?/)))
|
(6 (7 . ?/)))
|
||||||
("^=en\\(d\\)\\_>" 1 "!")
|
("^=en\\(d\\)\\_>" 1 "!")
|
||||||
;; General delimited string.
|
;; Percent literal.
|
||||||
("\\(^\\|[[ \t\n<+(,=]\\)\\(%[xrqQwW]?\\([^<[{(a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\3\\)\\)"
|
("\\(^\\|[[ \t\n<+(,=]\\)\\(%[xrqQwW]?\\([^<[{(a-zA-Z0-9 \n]\\)[^\n\\\\]*\\(\\\\.[^\n\\\\]*\\)*\\(\\3\\)\\)"
|
||||||
(3 "\"")
|
(3 "\"")
|
||||||
(5 "\""))
|
(5 "\""))
|
||||||
|
Loading…
Reference in New Issue
Block a user