aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes
diff options
context:
space:
mode:
authorGlenn Morris2013-01-24 20:41:39 -0800
committerGlenn Morris2013-01-24 20:41:39 -0800
commit830e46e61ba1316e771c72a15e709d3d12e150b7 (patch)
treec88c21c32f65dc77d8f76c315a41a519a585dc8f /lisp/progmodes
parent3d4147bae3f03502acb3d12a5c9747129cc0c6aa (diff)
parent345f866e048bdc11bc38d894a7eaaa47335443e2 (diff)
downloademacs-830e46e61ba1316e771c72a15e709d3d12e150b7.tar.gz
emacs-830e46e61ba1316e771c72a15e709d3d12e150b7.zip
Merge from emacs-24; up to 2012-12-11T18:52:31Z!monnier@iro.umontreal.ca
Diffstat (limited to 'lisp/progmodes')
-rw-r--r--lisp/progmodes/cc-engine.el104
-rw-r--r--lisp/progmodes/python.el5
2 files changed, 60 insertions, 49 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 560b66bf3b0..1eac45d06e0 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -2545,14 +2545,12 @@ comment at the start of cc-engine.el for more info."
2545 ;; 2545 ;;
2546 ;; The return value is a list, one of the following: 2546 ;; The return value is a list, one of the following:
2547 ;; 2547 ;;
2548 ;; o - ('forward CACHE-POS START-POINT) - scan forward from START-POINT, 2548 ;; o - ('forward START-POINT) - scan forward from START-POINT,
2549 ;; which is not less than CACHE-POS. 2549 ;; which is not less than the highest position in `c-state-cache' below here.
2550 ;; o - ('backward CACHE-POS nil) - scan backwards (from HERE). 2550 ;; o - ('backward nil) - scan backwards (from HERE).
2551 ;; o - ('BOD nil START-POINT) - scan forwards from START-POINT, which is at the 2551 ;; o - ('BOD START-POINT) - scan forwards from START-POINT, which is at the
2552 ;; top level. 2552 ;; top level.
2553 ;; o - ('IN-LIT nil nil) - point is inside the literal containing point-min. 2553 ;; o - ('IN-LIT nil) - point is inside the literal containing point-min.
2554 ;; , where CACHE-POS is the highest position recorded in `c-state-cache' at
2555 ;; or below HERE.
2556 (let ((cache-pos (c-get-cache-scan-pos here)) ; highest position below HERE in cache (or 1) 2554 (let ((cache-pos (c-get-cache-scan-pos here)) ; highest position below HERE in cache (or 1)
2557 BOD-pos ; position of 2nd BOD before HERE. 2555 BOD-pos ; position of 2nd BOD before HERE.
2558 strategy ; 'forward, 'backward, 'BOD, or 'IN-LIT. 2556 strategy ; 'forward, 'backward, 'BOD, or 'IN-LIT.
@@ -2590,7 +2588,6 @@ comment at the start of cc-engine.el for more info."
2590 2588
2591 (list 2589 (list
2592 strategy 2590 strategy
2593 (and (memq strategy '(forward backward)) cache-pos)
2594 (and (memq strategy '(forward BOD)) start-point)))) 2591 (and (memq strategy '(forward BOD)) start-point))))
2595 2592
2596 2593
@@ -2657,7 +2654,8 @@ comment at the start of cc-engine.el for more info."
2657 ;; reduce the time wasted in repeated fruitless searches in brace deserts. 2654 ;; reduce the time wasted in repeated fruitless searches in brace deserts.
2658 (save-excursion 2655 (save-excursion
2659 (save-restriction 2656 (save-restriction
2660 (let* (new-cons 2657 (let* ((here (point-max))
2658 new-cons
2661 (cache-pos (c-state-cache-top-lparen)) ; might be nil. 2659 (cache-pos (c-state-cache-top-lparen)) ; might be nil.
2662 (macro-start-or-from 2660 (macro-start-or-from
2663 (progn (goto-char from) 2661 (progn (goto-char from)
@@ -2692,6 +2690,7 @@ comment at the start of cc-engine.el for more info."
2692 ;; search bound, even though the algorithm below would skip 2690 ;; search bound, even though the algorithm below would skip
2693 ;; over the new paren pair. 2691 ;; over the new paren pair.
2694 (cache-lim (and cache-pos (< cache-pos from) cache-pos))) 2692 (cache-lim (and cache-pos (< cache-pos from) cache-pos)))
2693 (widen)
2695 (narrow-to-region 2694 (narrow-to-region
2696 (cond 2695 (cond
2697 ((and desert-lim cache-lim) 2696 ((and desert-lim cache-lim)
@@ -2711,16 +2710,18 @@ comment at the start of cc-engine.el for more info."
2711 (while 2710 (while
2712 (and (setq ce (scan-lists bra -1 -1)) ; back past )/]/}; might signal 2711 (and (setq ce (scan-lists bra -1 -1)) ; back past )/]/}; might signal
2713 (setq bra (scan-lists ce -1 1)) ; back past (/[/{; might signal 2712 (setq bra (scan-lists ce -1 1)) ; back past (/[/{; might signal
2714 (or (> ce upper-lim) 2713 (or (> bra here) ;(> ce here)
2715 (not (eq (char-after bra) ?\{)) 2714 (and
2716 (and (goto-char bra) 2715 (< ce here)
2717 (c-beginning-of-macro) 2716 (or (not (eq (char-after bra) ?\{))
2718 (< (point) macro-start-or-from)))))) 2717 (and (goto-char bra)
2718 (c-beginning-of-macro)
2719 (< (point) macro-start-or-from))))))))
2719 (and ce (< ce bra))) 2720 (and ce (< ce bra)))
2720 (setq bra ce)) ; If we just backed over an unbalanced closing 2721 (setq bra ce)) ; If we just backed over an unbalanced closing
2721 ; brace, ignore it. 2722 ; brace, ignore it.
2722 2723
2723 (if (and ce (< bra ce) (eq (char-after bra) ?\{)) 2724 (if (and ce (< ce here) (< bra ce) (eq (char-after bra) ?\{))
2724 ;; We've found the desired brace-pair. 2725 ;; We've found the desired brace-pair.
2725 (progn 2726 (progn
2726 (setq new-cons (cons bra (1+ ce))) 2727 (setq new-cons (cons bra (1+ ce)))
@@ -2734,7 +2735,11 @@ comment at the start of cc-engine.el for more info."
2734 (t (setq c-state-cache (cons new-cons c-state-cache))))) 2735 (t (setq c-state-cache (cons new-cons c-state-cache)))))
2735 2736
2736 ;; We haven't found a brace pair. Record this in the cache. 2737 ;; We haven't found a brace pair. Record this in the cache.
2737 (setq c-state-brace-pair-desert (cons cache-pos from)))))))) 2738 (setq c-state-brace-pair-desert
2739 (cons (if (and ce (< bra ce) (> ce here)) ; {..} straddling HERE?
2740 bra
2741 (point-min))
2742 (min here from)))))))))
2738 2743
2739(defsubst c-state-push-any-brace-pair (bra+1 macro-start-or-here) 2744(defsubst c-state-push-any-brace-pair (bra+1 macro-start-or-here)
2740 ;; If BRA+1 is nil, do nothing. Otherwise, BRA+1 is the buffer position 2745 ;; If BRA+1 is nil, do nothing. Otherwise, BRA+1 is the buffer position
@@ -2852,19 +2857,19 @@ comment at the start of cc-engine.el for more info."
2852 (paren+1) 2857 (paren+1)
2853 (t from))))) 2858 (t from)))))
2854 2859
2855(defun c-remove-stale-state-cache (good-pos pps-point) 2860(defun c-remove-stale-state-cache (start-point pps-point)
2856 ;; Remove stale entries from the `c-cache-state', i.e. those which will 2861 ;; Remove stale entries from the `c-cache-state', i.e. those which will
2857 ;; not be in it when it is amended for position (point-max). 2862 ;; not be in it when it is amended for position (point-max).
2858 ;; Additionally, the "outermost" open-brace entry before (point-max) 2863 ;; Additionally, the "outermost" open-brace entry before (point-max)
2859 ;; will be converted to a cons if the matching close-brace is scanned. 2864 ;; will be converted to a cons if the matching close-brace is scanned.
2860 ;; 2865 ;;
2861 ;; GOOD-POS is a "maximal" "safe position" - there must be no open 2866 ;; START-POINT is a "maximal" "safe position" - there must be no open
2862 ;; parens/braces/brackets between GOOD-POS and (point-max). 2867 ;; parens/braces/brackets between START-POINT and (point-max).
2863 ;; 2868 ;;
2864 ;; As a second thing, calculate the result of parse-partial-sexp at 2869 ;; As a second thing, calculate the result of parse-partial-sexp at
2865 ;; PPS-POINT, w.r.t. GOOD-POS. The motivation here is that 2870 ;; PPS-POINT, w.r.t. START-POINT. The motivation here is that
2866 ;; `c-state-cache-good-pos' may become PPS-POINT, but the caller may need to 2871 ;; `c-state-cache-good-pos' may become PPS-POINT, but the caller may need to
2867 ;; adjust it to get outside a string/comment. (Sorry about this! The code 2872 ;; adjust it to get outside a string/comment. (Sorry about this! The code
2868 ;; needs to be FAST). 2873 ;; needs to be FAST).
2869 ;; 2874 ;;
2870 ;; Return a list (GOOD-POS SCAN-BACK-POS PPS-STATE), where 2875 ;; Return a list (GOOD-POS SCAN-BACK-POS PPS-STATE), where
@@ -2872,7 +2877,9 @@ comment at the start of cc-engine.el for more info."
2872 ;; to be good (we aim for this to be as high as possible); 2877 ;; to be good (we aim for this to be as high as possible);
2873 ;; o - SCAN-BACK-POS, if not nil, indicates there may be a brace pair 2878 ;; o - SCAN-BACK-POS, if not nil, indicates there may be a brace pair
2874 ;; preceding POS which needs to be recorded in `c-state-cache'. It is a 2879 ;; preceding POS which needs to be recorded in `c-state-cache'. It is a
2875 ;; position to scan backwards from. 2880 ;; position to scan backwards from. It is the position of the "{" of the
2881 ;; last element to be removed from `c-state-cache', when that elt is a
2882 ;; cons, otherwise nil.
2876 ;; o - PPS-STATE is the parse-partial-sexp state at PPS-POINT. 2883 ;; o - PPS-STATE is the parse-partial-sexp state at PPS-POINT.
2877 (save-restriction 2884 (save-restriction
2878 (narrow-to-region 1 (point-max)) 2885 (narrow-to-region 1 (point-max))
@@ -2882,21 +2889,21 @@ comment at the start of cc-engine.el for more info."
2882 (goto-char (point-max)) 2889 (goto-char (point-max))
2883 (and (c-beginning-of-macro) 2890 (and (c-beginning-of-macro)
2884 (point)))) 2891 (point))))
2885 (good-pos-actual-macro-start ; Start of macro containing good-pos 2892 (start-point-actual-macro-start ; Start of macro containing
2886 ; or nil 2893 ; start-point or nil
2887 (and (< good-pos (point-max)) 2894 (and (< start-point (point-max))
2888 (save-excursion 2895 (save-excursion
2889 (goto-char good-pos) 2896 (goto-char start-point)
2890 (and (c-beginning-of-macro) 2897 (and (c-beginning-of-macro)
2891 (point))))) 2898 (point)))))
2892 (good-pos-actual-macro-end ; End of this macro, (maybe 2899 (start-point-actual-macro-end ; End of this macro, (maybe
2893 ; (point-max)), or nil. 2900 ; (point-max)), or nil.
2894 (and good-pos-actual-macro-start 2901 (and start-point-actual-macro-start
2895 (save-excursion 2902 (save-excursion
2896 (goto-char good-pos-actual-macro-start) 2903 (goto-char start-point-actual-macro-start)
2897 (c-end-of-macro) 2904 (c-end-of-macro)
2898 (point)))) 2905 (point))))
2899 pps-state ; Will be 9 or 10 elements long. 2906 pps-state ; Will be 9 or 10 elements long.
2900 pos 2907 pos
2901 upper-lim ; ,beyond which `c-state-cache' entries are removed 2908 upper-lim ; ,beyond which `c-state-cache' entries are removed
2902 scan-back-pos 2909 scan-back-pos
@@ -2926,15 +2933,15 @@ comment at the start of cc-engine.el for more info."
2926 ;; The next loop jumps forward out of a nested level of parens each 2933 ;; The next loop jumps forward out of a nested level of parens each
2927 ;; time round; the corresponding elements in `c-state-cache' are 2934 ;; time round; the corresponding elements in `c-state-cache' are
2928 ;; removed. `pos' is just after the brace-pair or the open paren at 2935 ;; removed. `pos' is just after the brace-pair or the open paren at
2929 ;; (car c-state-cache). There can be no open parens/braces/brackets 2936 ;; (car c-state-cache). There can be no open parens/braces/brackets
2930 ;; between `good-pos'/`good-pos-actual-macro-start' and (point-max), 2937 ;; between `start-point'/`start-point-actual-macro-start' and (point-max),
2931 ;; due to the interface spec to this function. 2938 ;; due to the interface spec to this function.
2932 (setq pos (if (and good-pos-actual-macro-end 2939 (setq pos (if (and start-point-actual-macro-end
2933 (not (eq good-pos-actual-macro-start 2940 (not (eq start-point-actual-macro-start
2934 in-macro-start))) 2941 in-macro-start)))
2935 (1+ good-pos-actual-macro-end) ; get outside the macro as 2942 (1+ start-point-actual-macro-end) ; get outside the macro as
2936 ; marked by a `category' text property. 2943 ; marked by a `category' text property.
2937 good-pos)) 2944 start-point))
2938 (goto-char pos) 2945 (goto-char pos)
2939 (while (and c-state-cache 2946 (while (and c-state-cache
2940 (< (point) (point-max))) 2947 (< (point) (point-max)))
@@ -2993,14 +3000,14 @@ comment at the start of cc-engine.el for more info."
2993 3000
2994 (list pos scan-back-pos pps-state))))) 3001 (list pos scan-back-pos pps-state)))))
2995 3002
2996(defun c-remove-stale-state-cache-backwards (here cache-pos) 3003(defun c-remove-stale-state-cache-backwards (here)
2997 ;; Strip stale elements of `c-state-cache' by moving backwards through the 3004 ;; Strip stale elements of `c-state-cache' by moving backwards through the
2998 ;; buffer, and inform the caller of the scenario detected. 3005 ;; buffer, and inform the caller of the scenario detected.
2999 ;; 3006 ;;
3000 ;; HERE is the position we're setting `c-state-cache' for. 3007 ;; HERE is the position we're setting `c-state-cache' for.
3001 ;; CACHE-POS is just after the latest recorded position in `c-state-cache' 3008 ;; CACHE-POS (a locally bound variable) is just after the latest recorded
3002 ;; before HERE, or a position at or near point-min which isn't in a 3009 ;; position in `c-state-cache' before HERE, or a position at or near
3003 ;; literal. 3010 ;; point-min which isn't in a literal.
3004 ;; 3011 ;;
3005 ;; This function must only be called only when (> `c-state-cache-good-pos' 3012 ;; This function must only be called only when (> `c-state-cache-good-pos'
3006 ;; HERE). Usually the gap between CACHE-POS and HERE is large. It is thus 3013 ;; HERE). Usually the gap between CACHE-POS and HERE is large. It is thus
@@ -3023,10 +3030,11 @@ comment at the start of cc-engine.el for more info."
3023 ;; The comments in this defun use "paren" to mean parenthesis or square 3030 ;; The comments in this defun use "paren" to mean parenthesis or square
3024 ;; bracket (as contrasted with a brace), and "(" and ")" likewise. 3031 ;; bracket (as contrasted with a brace), and "(" and ")" likewise.
3025 ;; 3032 ;;
3026 ;; . {..} (..) (..) ( .. { } ) (...) ( .... . ..) 3033 ;; . {..} (..) (..) ( .. { } ) (...) ( .... . ..)
3027 ;; | | | | | | 3034 ;; | | | | | |
3028 ;; CP E here D C good 3035 ;; CP E here D C good
3029 (let ((pos c-state-cache-good-pos) 3036 (let ((cache-pos (c-get-cache-scan-pos here)) ; highest position below HERE in cache (or 1)
3037 (pos c-state-cache-good-pos)
3030 pa ren ; positions of "(" and ")" 3038 pa ren ; positions of "(" and ")"
3031 dropped-cons ; whether the last element dropped from `c-state-cache' 3039 dropped-cons ; whether the last element dropped from `c-state-cache'
3032 ; was a cons (representing a brace-pair) 3040 ; was a cons (representing a brace-pair)
@@ -3263,7 +3271,8 @@ comment at the start of cc-engine.el for more info."
3263 cache-pos ; highest position below HERE already existing in 3271 cache-pos ; highest position below HERE already existing in
3264 ; cache (or 1). 3272 ; cache (or 1).
3265 good-pos 3273 good-pos
3266 start-point 3274 start-point ; (when scanning forward) a place below HERE where there
3275 ; are no open parens/braces between it and HERE.
3267 bopl-state 3276 bopl-state
3268 res 3277 res
3269 scan-backward-pos scan-forward-p) ; used for 'backward. 3278 scan-backward-pos scan-forward-p) ; used for 'backward.
@@ -3274,8 +3283,7 @@ comment at the start of cc-engine.el for more info."
3274 ;; Strategy? 3283 ;; Strategy?
3275 (setq res (c-parse-state-get-strategy here c-state-cache-good-pos) 3284 (setq res (c-parse-state-get-strategy here c-state-cache-good-pos)
3276 strategy (car res) 3285 strategy (car res)
3277 cache-pos (cadr res) 3286 start-point (cadr res))
3278 start-point (nth 2 res))
3279 3287
3280 (when (eq strategy 'BOD) 3288 (when (eq strategy 'BOD)
3281 (setq c-state-cache nil 3289 (setq c-state-cache nil
@@ -3302,7 +3310,7 @@ comment at the start of cc-engine.el for more info."
3302 good-pos))) 3310 good-pos)))
3303 3311
3304 ((eq strategy 'backward) 3312 ((eq strategy 'backward)
3305 (setq res (c-remove-stale-state-cache-backwards here cache-pos) 3313 (setq res (c-remove-stale-state-cache-backwards here)
3306 good-pos (car res) 3314 good-pos (car res)
3307 scan-backward-pos (cadr res) 3315 scan-backward-pos (cadr res)
3308 scan-forward-p (car (cddr res))) 3316 scan-forward-p (car (cddr res)))
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 0e5f4c82090..2f353feb323 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -155,7 +155,10 @@
155;; dabbrev. If you have `dabbrev-mode' activated and 155;; dabbrev. If you have `dabbrev-mode' activated and
156;; `python-skeleton-autoinsert' is set to t, then whenever you type 156;; `python-skeleton-autoinsert' is set to t, then whenever you type
157;; the name of any of those defined and hit SPC, they will be 157;; the name of any of those defined and hit SPC, they will be
158;; automatically expanded. 158;; automatically expanded. As an alternative you can use the defined
159;; skeleton commands: `python-skeleton-class', `python-skeleton-def'
160;; `python-skeleton-for', `python-skeleton-if', `python-skeleton-try'
161;; and `python-skeleton-while'.
159 162
160;; FFAP: You can find the filename for a given module when using ffap 163;; FFAP: You can find the filename for a given module when using ffap
161;; out of the box. This feature needs an inferior python shell 164;; out of the box. This feature needs an inferior python shell