Now on revision 111224. ------------------------------------------------------------ revno: 111224 committer: Dmitry Gutov branch nick: trunk timestamp: Fri 2012-12-14 10:58:15 +0400 message: * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-function): Extract `ruby-syntax-propertize-expansions'. (ruby-syntax-propertize-expansions): Only change syntax on certain string delimiters, to punctuation. This way the common functions like forward-word and thing-at-point still work. (ruby-match-expression-expansion): Improve readability. (ruby-block-contains-point): New function. (ruby-add-log-current-method): Handle several edge cases. * test/automated/ruby-mode-tests.el Rename one interpolation test; add three more. (ruby-with-temp-buffer): New macro, use it where appropriate. (ruby-add-log-current-method-examples): Use "_" for target point. Add four tests for ruby-add-log-current-method. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-12-14 04:55:23 +0000 +++ lisp/ChangeLog 2012-12-14 06:58:15 +0000 @@ -6,6 +6,8 @@ certain string delimiters, to punctuation. This way the common functions like forward-word and thing-at-point still work. (ruby-match-expression-expansion): Improve readability. + (ruby-block-contains-point): New function. + (ruby-add-log-current-method): Handle several edge cases. 2012-12-13 Juanma Barranquero === modified file 'lisp/progmodes/ruby-mode.el' --- lisp/progmodes/ruby-mode.el 2012-12-14 04:55:23 +0000 +++ lisp/progmodes/ruby-mode.el 2012-12-14 06:58:15 +0000 @@ -102,6 +102,10 @@ '"\\(def\\|class\\|module\\)" "Regexp to match the beginning of a defun, in the general sense.") +(defconst ruby-singleton-class-re + "class\\s *<<" + "Regexp to match the beginning of a singleton class context.") + (eval-and-compile (defconst ruby-here-doc-beg-re "\\(<\\)<\\(-\\)?\\(\\([a-zA-Z0-9_]+\\)\\|[\"]\\([^\"]+\\)[\"]\\|[']\\([^']+\\)[']\\)" @@ -384,7 +388,7 @@ (when pos (goto-char pos)) (forward-word -1) (and (or (bolp) (not (eq (char-before (point)) ?_))) - (looking-at "class\\s *<<")))) + (looking-at ruby-singleton-class-re)))) (defun ruby-expr-beg (&optional option) "Check if point is possibly at the beginning of an expression. @@ -1057,35 +1061,32 @@ See `add-log-current-defun-function'." (condition-case nil (save-excursion - (let (mname mlist (indent 0)) + (let ((indent 0) mname mlist + (start (point)) + (definition-re + (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+" + "\\(" + ;; \\. and :: for class methods + "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)" + "+\\)"))) ;; Get the current method definition (or class/module). - (if (re-search-backward - (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+" - "\\(" - ;; \\. and :: for class methods - "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)" - "+\\)") - nil t) - (progn - (setq mname (match-string 2)) - (unless (string-equal "def" (match-string 1)) - (setq mlist (list mname) mname nil)) - (goto-char (match-beginning 1)) - (setq indent (current-column)) - (beginning-of-line))) + (when (re-search-backward definition-re nil t) + (goto-char (match-beginning 1)) + (when (ruby-block-contains-point start) + ;; We're inside the method, class or module. + (setq mname (match-string 2)) + (unless (string-equal "def" (match-string 1)) + (setq mlist (list mname) mname nil))) + (setq indent (current-column)) + (beginning-of-line)) ;; Walk up the class/module nesting. (while (and (> indent 0) - (re-search-backward - (concat - "^[ \t]*\\(class\\|module\\)[ \t]+" - "\\([A-Z]" ruby-symbol-re "*\\)") - nil t)) + (re-search-backward definition-re nil t)) (goto-char (match-beginning 1)) - (if (< (current-column) indent) - (progn - (setq mlist (cons (match-string 2) mlist)) - (setq indent (current-column)) - (beginning-of-line)))) + (when (ruby-block-contains-point start) + (setq mlist (cons (match-string 2) mlist)) + (setq indent (current-column)) + (beginning-of-line))) ;; Process the method name. (when mname (let ((mn (split-string mname "\\.\\|::"))) @@ -1104,7 +1105,14 @@ (setcdr (last mlist) (butlast mn)) (setq mlist (butlast mn)))) (setq mname (concat "." (car (last mn))))) - (setq mname (concat "#" mname))))) + ;; See if the method is in singleton class context. + (let ((in-singleton-class + (when (re-search-forward ruby-singleton-class-re start t) + (goto-char (match-beginning 0)) + (ruby-block-contains-point start)))) + (setq mname (concat + (if in-singleton-class "." "#") + mname)))))) ;; Generate the string. (if (consp mlist) (setq mlist (mapconcat (function identity) mlist "::"))) @@ -1112,6 +1120,12 @@ (if mlist (concat mlist mname) mname) mlist))))) +(defun ruby-block-contains-point (pt) + (save-excursion + (save-match-data + (ruby-forward-sexp) + (> (point) pt)))) + (defun ruby-brace-to-do-end (orig end) (let (beg-marker end-marker) (goto-char end) === modified file 'test/ChangeLog' --- test/ChangeLog 2012-12-14 04:55:23 +0000 +++ test/ChangeLog 2012-12-14 06:58:15 +0000 @@ -2,6 +2,9 @@ * automated/ruby-mode-tests.el Rename one interpolation test; add three more. + (ruby-with-temp-buffer): New macro, use it where appropriate. + (ruby-add-log-current-method-examples): Use "_" for target point. + Add four new tests for ruby-add-log-current-method. 2012-12-11 Glenn Morris === modified file 'test/automated/ruby-mode-tests.el' --- test/automated/ruby-mode-tests.el 2012-12-14 04:55:23 +0000 +++ test/automated/ruby-mode-tests.el 2012-12-14 06:58:15 +0000 @@ -25,9 +25,7 @@ (defun ruby-should-indent (content column) "Assert indentation COLUMN on the last line of CONTENT." - (with-temp-buffer - (insert content) - (ruby-mode) + (ruby-with-temp-buffer content (ruby-indent-line) (should (= (current-indentation) column)))) @@ -35,12 +33,17 @@ "Assert that CONTENT turns into EXPECTED after the buffer is re-indented. The whitespace before and including \"|\" on each line is removed." - (with-temp-buffer - (insert (ruby-test-string content)) - (ruby-mode) + (ruby-with-temp-buffer (ruby-test-string content) (indent-region (point-min) (point-max)) (should (string= (ruby-test-string expected) (buffer-string))))) +(defmacro ruby-with-temp-buffer (contents &rest body) + (declare (indent 1) (debug t)) + `(with-temp-buffer + (insert ,contents) + (ruby-mode) + ,@body)) + (defun ruby-test-string (s &rest args) (apply 'format (replace-regexp-in-string "^[ \t]*|" "" s) args)) @@ -48,9 +51,7 @@ "Assert syntax state values at the end of CONTENT. VALUES-PLIST is a list with alternating index and value elements." - (with-temp-buffer - (insert content) - (ruby-mode) + (ruby-with-temp-buffer content (syntax-propertize (point)) (while values-plist (should (eq (nth (car values-plist) @@ -59,9 +60,7 @@ (setq values-plist (cddr values-plist))))) (defun ruby-assert-face (content pos face) - (with-temp-buffer - (insert content) - (ruby-mode) + (ruby-with-temp-buffer content (font-lock-fontify-buffer) (should (eq face (get-text-property pos 'face))))) @@ -226,17 +225,13 @@ |")) (ert-deftest ruby-move-to-block-stops-at-indentation () - (with-temp-buffer - (insert "def f\nend") + (ruby-with-temp-buffer "def f\nend" (beginning-of-line) - (ruby-mode) (ruby-move-to-block -1) (should (looking-at "^def")))) (ert-deftest ruby-toggle-block-to-do-end () - (with-temp-buffer - (insert "foo {|b|\n}") - (ruby-mode) + (ruby-with-temp-buffer "foo {|b|\n}" (beginning-of-line) (ruby-toggle-block) (should (string= "foo do |b|\nend" (buffer-string))))) @@ -254,9 +249,7 @@ (should (string= (cdr pair) (buffer-string)))))))) (ert-deftest ruby-toggle-block-to-multiline () - (with-temp-buffer - (insert "foo {|b| b + 1}") - (ruby-mode) + (ruby-with-temp-buffer "foo {|b| b + 1}" (beginning-of-line) (ruby-toggle-block) (should (string= "foo do |b|\n b + 1\nend" (buffer-string))))) @@ -295,9 +288,8 @@ (ert-deftest ruby-interpolation-keeps-non-quote-syntax () (let ((s "\"foo#{baz.tee}bar\"")) - (with-temp-buffer - (save-excursion - (insert s)) + (ruby-with-temp-buffer s + (goto-char (point-min)) (ruby-mode) (font-lock-fontify-buffer) (search-forward "tee") @@ -318,21 +310,66 @@ ("self.foo" . ".foo")))) (dolist (pair pairs) (let ((name (car pair)) - (value (cdr pair))) - (with-temp-buffer - (insert (ruby-test-string - "module M - | class C - | def %s - | end - | end - |end" - name)) - (ruby-mode) - (search-backward "def") - (forward-line) - (should (string= (ruby-add-log-current-method) - (format "M::C%s" value)))))))) + (value (cdr pair))) + (ruby-with-temp-buffer (ruby-test-string + "module M + | class C + | def %s + | _ + | end + | end + |end" + name) + (search-backward "_") + (forward-line) + (should (string= (ruby-add-log-current-method) + (format "M::C%s" value)))))))) + +(ert-deftest ruby-add-log-current-method-outside-of-method () + (ruby-with-temp-buffer (ruby-test-string + "module M + | class C + | def foo + | end + | _ + | end + |end") + (search-backward "_") + (should (string= (ruby-add-log-current-method)"M::C")))) + +(ert-deftest ruby-add-log-current-method-in-singleton-class () + (ruby-with-temp-buffer (ruby-test-string + "class C + | class << self + | def foo + | _ + | end + | end + |end") + (search-backward "_") + (should (string= (ruby-add-log-current-method) "C.foo")))) + +(ert-deftest ruby-add-log-current-method-namespace-shorthand () + (ruby-with-temp-buffer (ruby-test-string + "class C::D + | def foo + | _ + | end + |end") + (search-backward "_") + (should (string= (ruby-add-log-current-method) "C::D#foo")))) + +(ert-deftest ruby-add-log-current-method-after-inner-class () + (ruby-with-temp-buffer (ruby-test-string + "module M + | class C + | class D + | end + | _ + | end + |end") + (search-backward "_") + (should (string= (ruby-add-log-current-method) "M::C")))) (defvar ruby-block-test-example (ruby-test-string ------------------------------------------------------------ revno: 111223 committer: Dmitry Gutov branch nick: trunk timestamp: Fri 2012-12-14 08:55:23 +0400 message: * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize-function): Extract `ruby-syntax-propertize-expansions'. (ruby-syntax-propertize-expansions): Only change syntax on certain string delimiters, to punctuation. This way the common functions like forward-word and thing-at-point still work. * test/automated/ruby-mode-tests.el Rename one interpolation test; add three more. diff: === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2012-12-13 18:15:42 +0000 +++ lisp/ChangeLog 2012-12-14 04:55:23 +0000 @@ -1,3 +1,12 @@ +2012-12-14 Dmitry Gutov + + * progmodes/ruby-mode.el (ruby-syntax-propertize-function): + Extract `ruby-syntax-propertize-expansions'. + (ruby-syntax-propertize-expansions): Only change syntax on + certain string delimiters, to punctuation. This way the common + functions like forward-word and thing-at-point still work. + (ruby-match-expression-expansion): Improve readability. + 2012-12-13 Juanma Barranquero * emacs-lisp/edebug.el (edebug-unload-function): Make sure that === modified file 'lisp/progmodes/ruby-mode.el' --- lisp/progmodes/ruby-mode.el 2012-11-14 12:17:21 +0000 +++ lisp/progmodes/ruby-mode.el 2012-12-14 04:55:23 +0000 @@ -1253,18 +1253,7 @@ ((concat "\\(?:^\\|[[ \t\n<+(,=]\\)" ruby-percent-literal-beg-re) (1 (prog1 "|" (ruby-syntax-propertize-percent-literal end))))) (point) end) - (remove-text-properties start end '(ruby-expansion-match-data)) - (goto-char start) - ;; Find all expression expansions and - ;; - set the syntax of all text inside to whitespace, - ;; - save the match data to a text property, for font-locking later. - (while (re-search-forward ruby-expression-expansion-re end 'move) - (when (ruby-in-ppss-context-p 'string) - (put-text-property (match-beginning 2) (match-end 2) - 'syntax-table (string-to-syntax "-")) - (put-text-property (match-beginning 2) (1+ (match-beginning 2)) - 'ruby-expansion-match-data - (match-data))))) + (ruby-syntax-propertize-expansions start end)) (defun ruby-syntax-propertize-heredoc (limit) (let ((ppss (syntax-ppss)) @@ -1331,6 +1320,23 @@ (string-to-syntax "|"))) ;; Unclosed literal, leave the following text unpropertized. ((scan-error search-failed) (goto-char limit)))))) + + (defun ruby-syntax-propertize-expansions (start end) + (remove-text-properties start end '(ruby-expansion-match-data)) + (goto-char start) + ;; Find all expression expansions and + ;; - save the match data to a text property, for font-locking later, + ;; - set the syntax of all double quotes and backticks to puctuation. + (while (re-search-forward ruby-expression-expansion-re end 'move) + (let ((beg (match-beginning 2)) + (end (match-end 2))) + (when (and beg (save-excursion (nth 3 (syntax-ppss beg)))) + (put-text-property beg (1+ beg) 'ruby-expansion-match-data + (match-data)) + (goto-char beg) + (while (re-search-forward "[\"`]" end 'move) + (put-text-property (match-beginning 0) (match-end 0) + 'syntax-table (string-to-syntax "."))))))) ) ;; For Emacsen where syntax-propertize-rules is not (yet) available, @@ -1605,10 +1611,10 @@ "Additional expressions to highlight in Ruby mode.") (defun ruby-match-expression-expansion (limit) - (let ((prop 'ruby-expansion-match-data) pos value) - (when (and (setq pos (next-single-char-property-change (point) prop - nil limit)) - (> pos (point))) + (let* ((prop 'ruby-expansion-match-data) + (pos (next-single-char-property-change (point) prop nil limit)) + value) + (when (and pos (> pos (point))) (goto-char pos) (or (and (setq value (get-text-property pos prop)) (progn (set-match-data value) t)) === modified file 'test/ChangeLog' --- test/ChangeLog 2012-12-11 04:42:49 +0000 +++ test/ChangeLog 2012-12-14 04:55:23 +0000 @@ -1,3 +1,8 @@ +2012-12-14 Dmitry Gutov + + * automated/ruby-mode-tests.el + Rename one interpolation test; add three more. + 2012-12-11 Glenn Morris * automated/f90.el (f90-test-bug13138): New test. === modified file 'test/automated/ruby-mode-tests.el' --- test/automated/ruby-mode-tests.el 2012-12-02 06:06:32 +0000 +++ test/automated/ruby-mode-tests.el 2012-12-14 04:55:23 +0000 @@ -276,13 +276,33 @@ (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16 font-lock-variable-name-face)) -(ert-deftest ruby-interpolation-suppresses-syntax-inside () +(ert-deftest ruby-interpolation-suppresses-quotes-inside () (let ((s "\"
  • #{@files.join(\"
  • \")}
\"")) (ruby-assert-state s 8 nil) (ruby-assert-face s 9 font-lock-string-face) (ruby-assert-face s 10 font-lock-variable-name-face) (ruby-assert-face s 41 font-lock-string-face))) +(ert-deftest ruby-interpolation-suppresses-one-double-quote () + (let ((s "\"foo#{'\"'}\"")) + (ruby-assert-state s 8 nil) + (ruby-assert-face s 8 font-lock-variable-name-face) + (ruby-assert-face s 11 font-lock-string-face))) + +(ert-deftest ruby-interpolation-suppresses-one-backtick () + (let ((s "`as#{'`'}das`")) + (ruby-assert-state s 8 nil))) + +(ert-deftest ruby-interpolation-keeps-non-quote-syntax () + (let ((s "\"foo#{baz.tee}bar\"")) + (with-temp-buffer + (save-excursion + (insert s)) + (ruby-mode) + (font-lock-fontify-buffer) + (search-forward "tee") + (should (string= (thing-at-point 'symbol) "tee"))))) + (ert-deftest ruby-interpolation-inside-percent-literal-with-paren () :expected-result :failed (let ((s "%(^#{\")\"}^)")) ------------------------------------------------------------ revno: 111222 fixes bug: http://debbugs.gnu.org/13173 author: Akinori MUSHA committer: Glenn Morris branch nick: trunk timestamp: Thu 2012-12-13 20:26:47 -0800 message: sieve-mode font-lock fix (tiny change) * sieve-mode.el (sieve-font-lock-keywords): Keywords should be word delimited. diff: === modified file 'lisp/gnus/ChangeLog' --- lisp/gnus/ChangeLog 2012-12-12 22:22:31 +0000 +++ lisp/gnus/ChangeLog 2012-12-14 04:26:47 +0000 @@ -1,3 +1,8 @@ +2012-12-14 Akinori MUSHA (tiny change) + + * sieve-mode.el (sieve-font-lock-keywords): + Keywords should be word delimited. (Bug#13173) + 2012-12-12 Katsumi Yamaoka * gnus-art.el (gnus-article-browse-html-parts): Use
=== modified file 'lisp/gnus/sieve-mode.el' --- lisp/gnus/sieve-mode.el 2012-07-18 10:38:37 +0000 +++ lisp/gnus/sieve-mode.el 2012-12-14 04:26:47 +0000 @@ -131,14 +131,17 @@ (eval-when-compile (list ;; control commands - (cons (regexp-opt '("require" "if" "else" "elsif" "stop")) + (cons (regexp-opt '("require" "if" "else" "elsif" "stop") + 'words) 'sieve-control-commands-face) ;; action commands - (cons (regexp-opt '("fileinto" "redirect" "reject" "keep" "discard")) + (cons (regexp-opt '("fileinto" "redirect" "reject" "keep" "discard") + 'words) 'sieve-action-commands-face) ;; test commands (cons (regexp-opt '("address" "allof" "anyof" "exists" "false" - "true" "header" "not" "size" "envelope")) + "true" "header" "not" "size" "envelope") + 'words) 'sieve-test-commands-face) (cons "\\Sw+:\\sw+" 'sieve-tagged-arguments-face)))) ------------------------------------------------------------ revno: 111221 committer: Paul Eggert branch nick: trunk timestamp: Thu 2012-12-13 11:35:10 -0800 message: * fileio.c (Finsert_file_contents): Don't put tail into head area, as that confuses set-auto-coding, so insist on the head-read returning the full 1024 bytes. Let lseek compute the tail offset; less work for us. Do not ignore I/O errors when reading the tail. diff: === modified file 'src/ChangeLog' --- src/ChangeLog 2012-12-13 16:55:28 +0000 +++ src/ChangeLog 2012-12-13 19:35:10 +0000 @@ -1,5 +1,10 @@ 2012-12-13 Paul Eggert + * fileio.c (Finsert_file_contents): Don't put tail into head area, + as that confuses set-auto-coding, so insist on the head-read + returning the full 1024 bytes. Let lseek compute the tail offset; + less work for us. Do not ignore I/O errors when reading the tail. + * xdisp.c: Minor style fixes. (init_iterator): Hoist assignment out of if-expression. (markpos_of_region): Callers now test for sign, not for -1. === modified file 'src/fileio.c' --- src/fileio.c 2012-12-13 05:29:15 +0000 +++ src/fileio.c 2012-12-13 19:35:10 +0000 @@ -3487,12 +3487,14 @@ else { nread = emacs_read (fd, read_buf, 1024); - if (nread >= 0) + if (nread == 1024) { - if (lseek (fd, st.st_size - (1024 * 3), SEEK_SET) < 0) + int ntail; + if (lseek (fd, - (1024 * 3), SEEK_END) < 0) report_file_error ("Setting file position", Fcons (orig_filename, Qnil)); - nread += emacs_read (fd, read_buf + nread, 1024 * 3); + ntail = emacs_read (fd, read_buf + nread, 1024 * 3); + nread = ntail < 0 ? ntail : nread + ntail; } }