aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorGlenn Morris2014-07-12 10:53:29 -0700
committerGlenn Morris2014-07-12 10:53:29 -0700
commitb39c4d7b33952e0125fbefbcb3d9f528b6570f40 (patch)
tree17fd0630dacfe29b0c2486b9f5c923293e872a70 /lisp
parent2a0bae50e3611a6bd2d584f7a85677b74f1aa71b (diff)
parentfb02552638b0c653bfc3d269d879fdffba37bd31 (diff)
downloademacs-b39c4d7b33952e0125fbefbcb3d9f528b6570f40.tar.gz
emacs-b39c4d7b33952e0125fbefbcb3d9f528b6570f40.zip
Merge from emacs-24; up to 2014-06-22T05:00:14Z!dmantipov@yandex.ru
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog38
-rw-r--r--lisp/faces.el7
-rw-r--r--lisp/progmodes/python.el204
-rw-r--r--lisp/vc/log-edit.el78
-rw-r--r--lisp/vc/vc-dispatcher.el2
5 files changed, 202 insertions, 127 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index faa5a3dffff..db1f0481d62 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,41 @@
12014-07-12 Paul Eggert <eggert@cs.ucla.edu>
2
3 Fix bug: C-x v v discarded existing log message (Bug#17884).
4 * vc/vc-dispatcher.el (vc-log-edit):
5 Don't clobber an already-existing log message.
6
72014-07-12 Glenn Morris <rgm@gnu.org>
8
9 * vc/log-edit.el (log-edit-changelog-entries):
10 Check for a visited-but-never-saved ChangeLog.
11
122014-07-12 Stefan Monnier <monnier@iro.umontreal.ca>
13
14 * vc/log-edit.el (log-edit-changelog-entries): Don't both visiting
15 a non-existing file (bug#17970).
16
17 * faces.el (face-name): Undo last change.
18 (x-resolve-font-name): Don't call face-name (bug#17956).
19
202014-07-12 Fabián Ezequiel Gallina <fgallina@gnu.org>
21
22 Fix dedenters and electric colon handling. (Bug#15163)
23 * progmodes/python.el
24 (python-rx-constituents): Add dedenter and block-ender.
25 (python-indent-dedenters, python-indent-block-enders): Delete.
26 (python-indent-context): Return new case for dedenter-statement.
27 (python-indent-calculate-indentation): Handle new case.
28 (python-indent-calculate-levels): Fix levels calculation for
29 dedenter statements.
30 (python-indent-post-self-insert-function): Fix colon handling.
31 (python-info-dedenter-opening-block-message): New function.
32 (python-indent-line): Use it.
33 (python-info-closing-block)
34 (python-info-closing-block-message): Remove.
35 (python-info-dedenter-opening-block-position)
36 (python-info-dedenter-opening-block-positions)
37 (python-info-dedenter-statement-p): New functions.
38
12014-07-11 Dmitry Antipov <dmantipov@yandex.ru> 392014-07-11 Dmitry Antipov <dmantipov@yandex.ru>
2 40
3 * files.el (out-of-memory-warning-percentage): New defcustom. 41 * files.el (out-of-memory-warning-percentage): New defcustom.
diff --git a/lisp/faces.el b/lisp/faces.el
index bb77af0425e..d9239d9e1eb 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -370,10 +370,7 @@ If `inhibit-x-resources' is non-nil, this function does nothing."
370 370
371(defun face-name (face) 371(defun face-name (face)
372 "Return the name of face FACE." 372 "Return the name of face FACE."
373 (check-face face) 373 (symbol-name (check-face face)))
374 (if (symbolp face)
375 (symbol-name face)
376 face))
377 374
378 375
379(defun face-all-attributes (face &optional frame) 376(defun face-all-attributes (face &optional frame)
@@ -2749,8 +2746,6 @@ If PATTERN is nil, return the name of the frame's base font, which never
2749contains wildcards. 2746contains wildcards.
2750Given optional arguments FACE and FRAME, return a font which is 2747Given optional arguments FACE and FRAME, return a font which is
2751also the same size as FACE on FRAME, or fail." 2748also the same size as FACE on FRAME, or fail."
2752 (when face
2753 (setq face (face-name face)))
2754 (and (eq frame t) 2749 (and (eq frame t)
2755 (setq frame nil)) 2750 (setq frame nil))
2756 (if pattern 2751 (if pattern
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 065a182904f..1187636c663 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -321,6 +321,13 @@
321 (or "def" "class" "if" "elif" "else" "try" 321 (or "def" "class" "if" "elif" "else" "try"
322 "except" "finally" "for" "while" "with") 322 "except" "finally" "for" "while" "with")
323 symbol-end)) 323 symbol-end))
324 (dedenter . ,(rx symbol-start
325 (or "elif" "else" "except" "finally")
326 symbol-end))
327 (block-ender . ,(rx symbol-start
328 (or
329 "break" "continue" "pass" "raise" "return")
330 symbol-end))
324 (decorator . ,(rx line-start (* space) ?@ (any letter ?_) 331 (decorator . ,(rx line-start (* space) ?@ (any letter ?_)
325 (* (any word ?_)))) 332 (* (any word ?_))))
326 (defun . ,(rx symbol-start (or "def" "class") symbol-end)) 333 (defun . ,(rx symbol-start (or "def" "class") symbol-end))
@@ -630,18 +637,6 @@ It makes underscores and dots word constituent chars.")
630(defvar python-indent-levels '(0) 637(defvar python-indent-levels '(0)
631 "Levels of indentation available for `python-indent-line-function'.") 638 "Levels of indentation available for `python-indent-line-function'.")
632 639
633(defvar python-indent-dedenters '("else" "elif" "except" "finally")
634 "List of words that should be dedented.
635These make `python-indent-calculate-indentation' subtract the value of
636`python-indent-offset'.")
637
638(defvar python-indent-block-enders
639 '("break" "continue" "pass" "raise" "return")
640 "List of words that mark the end of a block.
641These make `python-indent-calculate-indentation' subtract the
642value of `python-indent-offset' when `python-indent-context' is
643AFTER-LINE.")
644
645(defun python-indent-guess-indent-offset () 640(defun python-indent-guess-indent-offset ()
646 "Guess and set `python-indent-offset' for the current buffer." 641 "Guess and set `python-indent-offset' for the current buffer."
647 (interactive) 642 (interactive)
@@ -692,6 +687,7 @@ Where status can be any of the following symbols:
692 * after-backslash: Previous line ends in a backslash 687 * after-backslash: Previous line ends in a backslash
693 * after-beginning-of-block: Point is after beginning of block 688 * after-beginning-of-block: Point is after beginning of block
694 * after-line: Point is after normal line 689 * after-line: Point is after normal line
690 * dedenter-statement: Point is on a dedenter statement.
695 * no-indent: Point is at beginning of buffer or other special case 691 * no-indent: Point is at beginning of buffer or other special case
696START is the buffer position where the sexp starts." 692START is the buffer position where the sexp starts."
697 (save-restriction 693 (save-restriction
@@ -746,6 +742,8 @@ START is the buffer position where the sexp starts."
746 (when (looking-at (python-rx block-start)) 742 (when (looking-at (python-rx block-start))
747 (point-marker))))) 743 (point-marker)))))
748 'after-beginning-of-block) 744 'after-beginning-of-block)
745 ((when (setq start (python-info-dedenter-statement-p))
746 'dedenter-statement))
749 ;; After normal line 747 ;; After normal line
750 ((setq start (save-excursion 748 ((setq start (save-excursion
751 (back-to-indentation) 749 (back-to-indentation)
@@ -776,8 +774,7 @@ START is the buffer position where the sexp starts."
776 (goto-char context-start) 774 (goto-char context-start)
777 (+ (current-indentation) python-indent-offset)) 775 (+ (current-indentation) python-indent-offset))
778 ;; When after a simple line just use previous line 776 ;; When after a simple line just use previous line
779 ;; indentation, in the case current line starts with a 777 ;; indentation.
780 ;; `python-indent-dedenters' de-indent one level.
781 (`after-line 778 (`after-line
782 (let* ((pair (save-excursion 779 (let* ((pair (save-excursion
783 (goto-char context-start) 780 (goto-char context-start)
@@ -785,25 +782,27 @@ START is the buffer position where the sexp starts."
785 (current-indentation) 782 (current-indentation)
786 (python-info-beginning-of-block-p)))) 783 (python-info-beginning-of-block-p))))
787 (context-indentation (car pair)) 784 (context-indentation (car pair))
788 (after-block-start-p (cdr pair)) 785 ;; TODO: Separate block enders into its own case.
789 (adjustment 786 (adjustment
790 (if (or (save-excursion 787 (if (save-excursion
791 (back-to-indentation) 788 (python-util-forward-comment -1)
792 (and 789 (python-nav-beginning-of-statement)
793 ;; De-indent only when dedenters are not 790 (looking-at (python-rx block-ender)))
794 ;; next to a block start. This allows
795 ;; one-liner constructs such as:
796 ;; if condition: print "yay"
797 ;; else: print "wry"
798 (not after-block-start-p)
799 (looking-at (regexp-opt python-indent-dedenters))))
800 (save-excursion
801 (python-util-forward-comment -1)
802 (python-nav-beginning-of-statement)
803 (looking-at (regexp-opt python-indent-block-enders))))
804 python-indent-offset 791 python-indent-offset
805 0))) 792 0)))
806 (- context-indentation adjustment))) 793 (- context-indentation adjustment)))
794 ;; When point is on a dedenter statement, search for the
795 ;; opening block that corresponds to it and use its
796 ;; indentation. If no opening block is found just remove
797 ;; indentation as this is an invalid python file.
798 (`dedenter-statement
799 (let ((block-start-point
800 (python-info-dedenter-opening-block-position)))
801 (save-excursion
802 (if (not block-start-point)
803 0
804 (goto-char block-start-point)
805 (current-indentation)))))
807 ;; When inside of a string, do nothing. just use the current 806 ;; When inside of a string, do nothing. just use the current
808 ;; indentation. XXX: perhaps it would be a good idea to 807 ;; indentation. XXX: perhaps it would be a good idea to
809 ;; invoke standard text indentation here 808 ;; invoke standard text indentation here
@@ -930,16 +929,25 @@ START is the buffer position where the sexp starts."
930 929
931(defun python-indent-calculate-levels () 930(defun python-indent-calculate-levels ()
932 "Calculate `python-indent-levels' and reset `python-indent-current-level'." 931 "Calculate `python-indent-levels' and reset `python-indent-current-level'."
933 (let* ((indentation (python-indent-calculate-indentation)) 932 (if (not (python-info-dedenter-statement-p))
934 (remainder (% indentation python-indent-offset)) 933 (let* ((indentation (python-indent-calculate-indentation))
935 (steps (/ (- indentation remainder) python-indent-offset))) 934 (remainder (% indentation python-indent-offset))
936 (setq python-indent-levels (list 0)) 935 (steps (/ (- indentation remainder) python-indent-offset)))
937 (dotimes (step steps) 936 (setq python-indent-levels (list 0))
938 (push (* python-indent-offset (1+ step)) python-indent-levels)) 937 (dotimes (step steps)
939 (when (not (eq 0 remainder)) 938 (push (* python-indent-offset (1+ step)) python-indent-levels))
940 (push (+ (* python-indent-offset steps) remainder) python-indent-levels)) 939 (when (not (eq 0 remainder))
941 (setq python-indent-levels (nreverse python-indent-levels)) 940 (push (+ (* python-indent-offset steps) remainder) python-indent-levels)))
942 (setq python-indent-current-level (1- (length python-indent-levels))))) 941 (setq python-indent-levels
942 (or
943 (mapcar (lambda (pos)
944 (save-excursion
945 (goto-char pos)
946 (current-indentation)))
947 (python-info-dedenter-opening-block-positions))
948 (list 0))))
949 (setq python-indent-current-level (1- (length python-indent-levels))
950 python-indent-levels (nreverse python-indent-levels)))
943 951
944(defun python-indent-toggle-levels () 952(defun python-indent-toggle-levels ()
945 "Toggle `python-indent-current-level' over `python-indent-levels'." 953 "Toggle `python-indent-current-level' over `python-indent-levels'."
@@ -988,7 +996,7 @@ equal to
988 (indent-to next-indent) 996 (indent-to next-indent)
989 (goto-char starting-pos)) 997 (goto-char starting-pos))
990 (and follow-indentation-p (back-to-indentation))) 998 (and follow-indentation-p (back-to-indentation)))
991 (python-info-closing-block-message)) 999 (python-info-dedenter-opening-block-message))
992 1000
993(defun python-indent-line-function () 1001(defun python-indent-line-function ()
994 "`indent-line-function' for Python mode. 1002 "`indent-line-function' for Python mode.
@@ -1124,14 +1132,7 @@ the line will be re-indented automatically if needed."
1124 (eolp) 1132 (eolp)
1125 (not (equal ?: (char-before (1- (point))))) 1133 (not (equal ?: (char-before (1- (point)))))
1126 (not (python-syntax-comment-or-string-p))) 1134 (not (python-syntax-comment-or-string-p)))
1127 (let ((indentation (current-indentation)) 1135 (python-indent-line)))))
1128 (calculated-indentation (python-indent-calculate-indentation)))
1129 (python-info-closing-block-message)
1130 (when (> indentation calculated-indentation)
1131 (save-excursion
1132 (indent-line-to calculated-indentation)
1133 (when (not (python-info-closing-block-message))
1134 (indent-line-to indentation)))))))))
1135 1136
1136 1137
1137;;; Navigation 1138;;; Navigation
@@ -3454,49 +3455,88 @@ parent defun name."
3454 (and (python-info-end-of-statement-p) 3455 (and (python-info-end-of-statement-p)
3455 (python-info-statement-ends-block-p))) 3456 (python-info-statement-ends-block-p)))
3456 3457
3457(defun python-info-closing-block () 3458(define-obsolete-function-alias
3458 "Return the point of the block the current line closes." 3459 'python-info-closing-block
3459 (let ((closing-word (save-excursion 3460 'python-info-dedenter-opening-block-position "24.4")
3460 (back-to-indentation) 3461
3461 (current-word))) 3462(defun python-info-dedenter-opening-block-position ()
3462 (indentation (current-indentation))) 3463 "Return the point of the closest block the current line closes.
3463 (when (member closing-word python-indent-dedenters) 3464Returns nil if point is not on a dedenter statement or no opening
3465block can be detected. The latter case meaning current file is
3466likely an invalid python file."
3467 (let ((positions (python-info-dedenter-opening-block-positions))
3468 (indentation (current-indentation))
3469 (position))
3470 (while (and (not position)
3471 positions)
3464 (save-excursion 3472 (save-excursion
3465 (forward-line -1) 3473 (goto-char (car positions))
3466 (while (and (> (current-indentation) indentation) 3474 (if (<= (current-indentation) indentation)
3467 (not (bobp)) 3475 (setq position (car positions))
3468 (not (back-to-indentation)) 3476 (setq positions (cdr positions)))))
3469 (forward-line -1))) 3477 position))
3470 (back-to-indentation) 3478
3471 (cond 3479(defun python-info-dedenter-opening-block-positions ()
3472 ((not (equal indentation (current-indentation))) nil) 3480 "Return points of blocks the current line may close sorted by closer.
3473 ((string= closing-word "elif") 3481Returns nil if point is not on a dedenter statement or no opening
3474 (when (member (current-word) '("if" "elif")) 3482block can be detected. The latter case meaning current file is
3475 (point-marker))) 3483likely an invalid python file."
3476 ((string= closing-word "else") 3484 (save-excursion
3477 (when (member (current-word) '("if" "elif" "except" "for" "while")) 3485 (let ((dedenter-pos (python-info-dedenter-statement-p)))
3478 (point-marker))) 3486 (when dedenter-pos
3479 ((string= closing-word "except") 3487 (goto-char dedenter-pos)
3480 (when (member (current-word) '("try")) 3488 (let* ((pairs '(("elif" "elif" "if")
3481 (point-marker))) 3489 ("else" "if" "elif" "except" "for" "while")
3482 ((string= closing-word "finally") 3490 ("except" "except" "try")
3483 (when (member (current-word) '("except" "else")) 3491 ("finally" "else" "except" "try")))
3484 (point-marker)))))))) 3492 (dedenter (match-string-no-properties 0))
3485 3493 (possible-opening-blocks (cdr (assoc-string dedenter pairs)))
3486(defun python-info-closing-block-message (&optional closing-block-point) 3494 (collected-indentations)
3487 "Message the contents of the block the current line closes. 3495 (opening-blocks))
3488With optional argument CLOSING-BLOCK-POINT use that instead of 3496 (catch 'exit
3489recalculating it calling `python-info-closing-block'." 3497 (while (python-nav--syntactically
3490 (let ((point (or closing-block-point (python-info-closing-block)))) 3498 (lambda ()
3499 (re-search-backward (python-rx block-start) nil t))
3500 #'<)
3501 (let ((indentation (current-indentation)))
3502 (when (and (not (memq indentation collected-indentations))
3503 (or (not collected-indentations)
3504 (< indentation (apply #'min collected-indentations))))
3505 (setq collected-indentations
3506 (cons indentation collected-indentations))
3507 (when (member (match-string-no-properties 0)
3508 possible-opening-blocks)
3509 (setq opening-blocks (cons (point) opening-blocks))))
3510 (when (zerop indentation)
3511 (throw 'exit nil)))))
3512 ;; sort by closer
3513 (nreverse opening-blocks))))))
3514
3515(define-obsolete-function-alias
3516 'python-info-closing-block-message
3517 'python-info-dedenter-opening-block-message "24.4")
3518
3519(defun python-info-dedenter-opening-block-message ()
3520 "Message the first line of the block the current statement closes."
3521 (let ((point (python-info-dedenter-opening-block-position)))
3491 (when point 3522 (when point
3492 (save-restriction 3523 (save-restriction
3493 (widen) 3524 (widen)
3494 (message "Closes %s" (save-excursion 3525 (message "Closes %s" (save-excursion
3495 (goto-char point) 3526 (goto-char point)
3496 (back-to-indentation)
3497 (buffer-substring 3527 (buffer-substring
3498 (point) (line-end-position)))))))) 3528 (point) (line-end-position))))))))
3499 3529
3530(defun python-info-dedenter-statement-p ()
3531 "Return point if current statement is a dedenter.
3532Sets `match-data' to the keyword that starts the dedenter
3533statement."
3534 (save-excursion
3535 (python-nav-beginning-of-statement)
3536 (when (and (not (python-syntax-context-type))
3537 (looking-at (python-rx dedenter)))
3538 (point))))
3539
3500(defun python-info-line-ends-backslash-p (&optional line-number) 3540(defun python-info-line-ends-backslash-p (&optional line-number)
3501 "Return non-nil if current line ends with backslash. 3541 "Return non-nil if current line ends with backslash.
3502With optional argument LINE-NUMBER, check that line instead." 3542With optional argument LINE-NUMBER, check that line instead."
diff --git a/lisp/vc/log-edit.el b/lisp/vc/log-edit.el
index 1d75411ec1f..3b03ee14c0b 100644
--- a/lisp/vc/log-edit.el
+++ b/lisp/vc/log-edit.el
@@ -905,44 +905,46 @@ where LOGBUFFER is the name of the ChangeLog buffer, and each
905 ;; that memoizing which is undesired here. 905 ;; that memoizing which is undesired here.
906 (setq change-log-default-name nil) 906 (setq change-log-default-name nil)
907 (find-change-log))))) 907 (find-change-log)))))
908 (with-current-buffer (find-file-noselect changelog-file-name) 908 (when (or (find-buffer-visiting changelog-file-name)
909 (unless (eq major-mode 'change-log-mode) (change-log-mode)) 909 (file-exists-p changelog-file-name))
910 (goto-char (point-min)) 910 (with-current-buffer (find-file-noselect changelog-file-name)
911 (if (looking-at "\\s-*\n") (goto-char (match-end 0))) 911 (unless (eq major-mode 'change-log-mode) (change-log-mode))
912 (if (not (log-edit-changelog-ours-p)) 912 (goto-char (point-min))
913 (list (current-buffer)) 913 (if (looking-at "\\s-*\n") (goto-char (match-end 0)))
914 (save-restriction 914 (if (not (log-edit-changelog-ours-p))
915 (log-edit-narrow-changelog) 915 (list (current-buffer))
916 (goto-char (point-min)) 916 (save-restriction
917 917 (log-edit-narrow-changelog)
918 ;; Search for the name of FILE relative to the ChangeLog. If that 918 (goto-char (point-min))
919 ;; doesn't occur anywhere, they're not using full relative 919
920 ;; filenames in the ChangeLog, so just look for FILE; we'll accept 920 ;; Search for the name of FILE relative to the ChangeLog. If that
921 ;; some false positives. 921 ;; doesn't occur anywhere, they're not using full relative
922 (let ((pattern (file-relative-name 922 ;; filenames in the ChangeLog, so just look for FILE; we'll accept
923 file (file-name-directory changelog-file-name)))) 923 ;; some false positives.
924 (if (or (string= pattern "") 924 (let ((pattern (file-relative-name
925 (not (save-excursion 925 file (file-name-directory changelog-file-name))))
926 (search-forward pattern nil t)))) 926 (if (or (string= pattern "")
927 (setq pattern (file-name-nondirectory file))) 927 (not (save-excursion
928 928 (search-forward pattern nil t))))
929 (setq pattern (concat "\\(^\\|[^[:alnum:]]\\)" 929 (setq pattern (file-name-nondirectory file)))
930 (regexp-quote pattern) 930
931 "\\($\\|[^[:alnum:]]\\)")) 931 (setq pattern (concat "\\(^\\|[^[:alnum:]]\\)"
932 932 (regexp-quote pattern)
933 (let (texts 933 "\\($\\|[^[:alnum:]]\\)"))
934 (pos (point))) 934
935 (while (and (not (eobp)) (re-search-forward pattern nil t)) 935 (let (texts
936 (let ((entry (log-edit-changelog-entry))) 936 (pos (point)))
937 (if (< (elt entry 1) (max (1+ pos) (point))) 937 (while (and (not (eobp)) (re-search-forward pattern nil t))
938 ;; This is not relevant, actually. 938 (let ((entry (log-edit-changelog-entry)))
939 nil 939 (if (< (elt entry 1) (max (1+ pos) (point)))
940 (push entry texts)) 940 ;; This is not relevant, actually.
941 ;; Make sure we make progress. 941 nil
942 (setq pos (max (1+ pos) (elt entry 1))) 942 (push entry texts))
943 (goto-char pos))) 943 ;; Make sure we make progress.
944 944 (setq pos (max (1+ pos) (elt entry 1)))
945 (cons (current-buffer) texts)))))))) 945 (goto-char pos)))
946
947 (cons (current-buffer) texts)))))))))
946 948
947(defun log-edit-changelog-insert-entries (buffer beg end &rest files) 949(defun log-edit-changelog-insert-entries (buffer beg end &rest files)
948 "Insert the text from BUFFER between BEG and END. 950 "Insert the text from BUFFER between BEG and END.
diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el
index a0efe023a1d..0445891ed55 100644
--- a/lisp/vc/vc-dispatcher.el
+++ b/lisp/vc/vc-dispatcher.el
@@ -596,7 +596,7 @@ NOT-URGENT means it is ok to continue if the user says not to save."
596 (setq default-directory 596 (setq default-directory
597 (buffer-local-value 'default-directory vc-parent-buffer)) 597 (buffer-local-value 'default-directory vc-parent-buffer))
598 (log-edit 'vc-finish-logentry 598 (log-edit 'vc-finish-logentry
599 t 599 (= (point-min) (point-max))
600 `((log-edit-listfun . (lambda () 600 `((log-edit-listfun . (lambda ()
601 ;; FIXME: Should expand the list 601 ;; FIXME: Should expand the list
602 ;; for directories. 602 ;; for directories.