Mercurial > emacs
comparison lisp/simple.el @ 84609:653c328271e7
(newline): Simplify use of prefix-numeric-value.
(line-move-partial): Remove unused var `ppos'.
(line-move-1): Replace 9999 with most-positive-fixnum.
(move-end-of-line): Use more efficient single-property search.
(move-beginning-of-line): Remove unused var `start'.
(blink-matching-open): Restructure in a more functional style.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sun, 16 Sep 2007 22:11:33 +0000 |
parents | 38640f40d45e |
children | b3ee425c3884 |
comparison
equal
deleted
inserted
replaced
84608:2768a568e11e | 84609:653c328271e7 |
---|---|
455 ;; thinks he inserted. | 455 ;; thinks he inserted. |
456 | 456 |
457 ;; Mark the newline(s) `hard'. | 457 ;; Mark the newline(s) `hard'. |
458 (if use-hard-newlines | 458 (if use-hard-newlines |
459 (set-hard-newline-properties | 459 (set-hard-newline-properties |
460 (- (point) (if arg (prefix-numeric-value arg) 1)) (point))) | 460 (- (point) (prefix-numeric-value arg)) (point))) |
461 ;; If the newline leaves the previous line blank, | 461 ;; If the newline leaves the previous line blank, |
462 ;; and we have a left margin, delete that from the blank line. | 462 ;; and we have a left margin, delete that from the blank line. |
463 (or flag | 463 (or flag |
464 (save-excursion | 464 (save-excursion |
465 (goto-char beforepos) | 465 (goto-char beforepos) |
1041 (or (not (memq this-command '(eval-last-sexp eval-print-last-sexp))) | 1041 (or (not (memq this-command '(eval-last-sexp eval-print-last-sexp))) |
1042 (eq this-command last-command) | 1042 (eq this-command last-command) |
1043 (if (boundp 'edebug-active) edebug-active))) | 1043 (if (boundp 'edebug-active) edebug-active))) |
1044 (let ((char-string | 1044 (let ((char-string |
1045 (if (or (if (boundp 'edebug-active) edebug-active) | 1045 (if (or (if (boundp 'edebug-active) edebug-active) |
1046 (memq this-command '(eval-last-sexp eval-print-last-sexp))) | 1046 (memq this-command '(eval-last-sexp eval-print-last-sexp))) |
1047 (prin1-char value)))) | 1047 (prin1-char value)))) |
1048 (if char-string | 1048 (if char-string |
1049 (format " (#o%o, #x%x, %s)" value value char-string) | 1049 (format " (#o%o, #x%x, %s)" value value char-string) |
1050 (format " (#o%o, #x%x)" value value))))) | 1050 (format " (#o%o, #x%x)" value value))))) |
1051 | 1051 |
2813 | 2813 |
2814 ;; This is actually used in subr.el but defcustom does not work there. | 2814 ;; This is actually used in subr.el but defcustom does not work there. |
2815 (defcustom yank-excluded-properties | 2815 (defcustom yank-excluded-properties |
2816 '(read-only invisible intangible field mouse-face help-echo local-map keymap | 2816 '(read-only invisible intangible field mouse-face help-echo local-map keymap |
2817 yank-handler follow-link fontified) | 2817 yank-handler follow-link fontified) |
2818 "*Text properties to discard when yanking. | 2818 "Text properties to discard when yanking. |
2819 The value should be a list of text properties to discard or t, | 2819 The value should be a list of text properties to discard or t, |
2820 which means to discard all text properties." | 2820 which means to discard all text properties." |
2821 :type '(choice (const :tag "All" t) (repeat symbol)) | 2821 :type '(choice (const :tag "All" t) (repeat symbol)) |
2822 :group 'killing | 2822 :group 'killing |
2823 :version "22.1") | 2823 :version "22.1") |
3621 | 3621 |
3622 (defvar temporary-goal-column 0 | 3622 (defvar temporary-goal-column 0 |
3623 "Current goal column for vertical motion. | 3623 "Current goal column for vertical motion. |
3624 It is the column where point was | 3624 It is the column where point was |
3625 at the start of current run of vertical motion commands. | 3625 at the start of current run of vertical motion commands. |
3626 When the `track-eol' feature is doing its job, the value is 9999.") | 3626 When the `track-eol' feature is doing its job, the value is `most-positive-fixnum'.") |
3627 | 3627 |
3628 (defcustom line-move-ignore-invisible t | 3628 (defcustom line-move-ignore-invisible t |
3629 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines. | 3629 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines. |
3630 Outline mode sets this." | 3630 Outline mode sets this." |
3631 :type 'boolean | 3631 :type 'boolean |
3643 ;; Move forward (down). | 3643 ;; Move forward (down). |
3644 (let* ((lh (window-line-height -1)) | 3644 (let* ((lh (window-line-height -1)) |
3645 (vpos (nth 1 lh)) | 3645 (vpos (nth 1 lh)) |
3646 (ypos (nth 2 lh)) | 3646 (ypos (nth 2 lh)) |
3647 (rbot (nth 3 lh)) | 3647 (rbot (nth 3 lh)) |
3648 ppos py vs) | 3648 py vs) |
3649 (when (or (null lh) | 3649 (when (or (null lh) |
3650 (>= rbot (frame-char-height)) | 3650 (>= rbot (frame-char-height)) |
3651 (<= ypos (- (frame-char-height)))) | 3651 (<= ypos (- (frame-char-height)))) |
3652 (unless lh | 3652 (unless lh |
3653 (let ((wend (pos-visible-in-window-p t nil t))) | 3653 (let ((wend (pos-visible-in-window-p t nil t))) |
3720 (setq temporary-goal-column | 3720 (setq temporary-goal-column |
3721 (if (and track-eol (eolp) | 3721 (if (and track-eol (eolp) |
3722 ;; Don't count beg of empty line as end of line | 3722 ;; Don't count beg of empty line as end of line |
3723 ;; unless we just did explicit end-of-line. | 3723 ;; unless we just did explicit end-of-line. |
3724 (or (not (bolp)) (eq last-command 'move-end-of-line))) | 3724 (or (not (bolp)) (eq last-command 'move-end-of-line))) |
3725 9999 | 3725 most-positive-fixnum |
3726 (current-column)))) | 3726 (current-column)))) |
3727 | 3727 |
3728 (if (and (not (integerp selective-display)) | 3728 (if (not (or (integerp selective-display) |
3729 (not line-move-ignore-invisible)) | 3729 line-move-ignore-invisible)) |
3730 ;; Use just newline characters. | 3730 ;; Use just newline characters. |
3731 ;; Set ARG to 0 if we move as many lines as requested. | 3731 ;; Set ARG to 0 if we move as many lines as requested. |
3732 (or (if (> arg 0) | 3732 (or (if (> arg 0) |
3733 (progn (if (> arg 1) (forward-line (1- arg))) | 3733 (progn (if (> arg 1) (forward-line (1- arg))) |
3734 ;; This way of moving forward ARG lines | 3734 ;; This way of moving forward ARG lines |
3963 (let ((goal-column 0)) | 3963 (let ((goal-column 0)) |
3964 (and (line-move arg t) | 3964 (and (line-move arg t) |
3965 (not (bobp)) | 3965 (not (bobp)) |
3966 (progn | 3966 (progn |
3967 (while (and (not (bobp)) (invisible-p (1- (point)))) | 3967 (while (and (not (bobp)) (invisible-p (1- (point)))) |
3968 (goto-char (previous-char-property-change (point)))) | 3968 (goto-char (previous-single-char-property-change |
3969 (point) 'invisible))) | |
3969 (backward-char 1))) | 3970 (backward-char 1))) |
3970 (point))))) | 3971 (point))))) |
3971 (goto-char newpos) | 3972 (goto-char newpos) |
3972 (if (and (> (point) newpos) | 3973 (if (and (> (point) newpos) |
3973 (eq (preceding-char) ?\n)) | 3974 (eq (preceding-char) ?\n)) |
3990 To ignore intangibility, bind `inhibit-point-motion-hooks' to t." | 3991 To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
3991 (interactive "p") | 3992 (interactive "p") |
3992 (or arg (setq arg 1)) | 3993 (or arg (setq arg 1)) |
3993 | 3994 |
3994 (let ((orig (point)) | 3995 (let ((orig (point)) |
3995 start first-vis first-vis-field-value) | 3996 first-vis first-vis-field-value) |
3996 | 3997 |
3997 ;; Move by lines, if ARG is not 1 (the default). | 3998 ;; Move by lines, if ARG is not 1 (the default). |
3998 (if (/= arg 1) | 3999 (if (/= arg 1) |
3999 (line-move (1- arg) t)) | 4000 (line-move (1- arg) t)) |
4000 | 4001 |
4001 ;; Move to beginning-of-line, ignoring fields and invisibles. | 4002 ;; Move to beginning-of-line, ignoring fields and invisibles. |
4002 (skip-chars-backward "^\n") | 4003 (skip-chars-backward "^\n") |
4003 (while (and (not (bobp)) (invisible-p (1- (point)))) | 4004 (while (and (not (bobp)) (invisible-p (1- (point)))) |
4004 (goto-char (previous-char-property-change (point))) | 4005 (goto-char (previous-char-property-change (point))) |
4005 (skip-chars-backward "^\n")) | 4006 (skip-chars-backward "^\n")) |
4006 (setq start (point)) | |
4007 | 4007 |
4008 ;; Now find first visible char in the line | 4008 ;; Now find first visible char in the line |
4009 (while (and (not (eobp)) (invisible-p (point))) | 4009 (while (and (not (eobp)) (invisible-p (point))) |
4010 (goto-char (next-char-property-change (point)))) | 4010 (goto-char (next-char-property-change (point)))) |
4011 (setq first-vis (point)) | 4011 (setq first-vis (point)) |
4652 (save-excursion | 4652 (save-excursion |
4653 (forward-char -1) | 4653 (forward-char -1) |
4654 (skip-syntax-backward "/\\") | 4654 (skip-syntax-backward "/\\") |
4655 (point)))))) | 4655 (point)))))) |
4656 (let* ((oldpos (point)) | 4656 (let* ((oldpos (point)) |
4657 blinkpos | 4657 (message-log-max nil) ; Don't log messages about paren matching. |
4658 message-log-max ; Don't log messages about paren matching. | 4658 (blinkpos |
4659 matching-paren | 4659 (save-excursion |
4660 open-paren-line-string) | 4660 (save-restriction |
4661 (save-excursion | 4661 (if blink-matching-paren-distance |
4662 (save-restriction | 4662 (narrow-to-region |
4663 (if blink-matching-paren-distance | 4663 (max (minibuffer-prompt-end) ;(point-min) unless minibuf. |
4664 (narrow-to-region (max (minibuffer-prompt-end) | 4664 (- (point) blink-matching-paren-distance)) |
4665 (- (point) blink-matching-paren-distance)) | 4665 oldpos)) |
4666 oldpos)) | 4666 (let ((parse-sexp-ignore-comments |
4667 (condition-case () | 4667 (and parse-sexp-ignore-comments |
4668 (let ((parse-sexp-ignore-comments | 4668 (not blink-matching-paren-dont-ignore-comments)))) |
4669 (and parse-sexp-ignore-comments | 4669 (condition-case () |
4670 (not blink-matching-paren-dont-ignore-comments)))) | 4670 (scan-sexps oldpos -1) |
4671 (setq blinkpos (scan-sexps oldpos -1))) | 4671 (error nil)))))) |
4672 (error nil))) | 4672 (matching-paren |
4673 (and blinkpos | 4673 (and blinkpos |
4674 ;; Not syntax '$'. | 4674 ;; Not syntax '$'. |
4675 (not (eq (syntax-class (syntax-after blinkpos)) 8)) | 4675 (not (eq (syntax-class (syntax-after blinkpos)) 8)) |
4676 (setq matching-paren | 4676 (let ((syntax (syntax-after blinkpos))) |
4677 (let ((syntax (syntax-after blinkpos))) | 4677 (and (consp syntax) |
4678 (and (consp syntax) | 4678 (eq (syntax-class syntax) 4) |
4679 (eq (syntax-class syntax) 4) | 4679 (cdr syntax)))))) |
4680 (cdr syntax))))) | 4680 (cond |
4681 (cond | 4681 ((not (or (eq matching-paren (char-before oldpos)) |
4682 ((not (or (eq matching-paren (char-before oldpos)) | 4682 ;; The cdr might hold a new paren-class info rather than |
4683 ;; The cdr might hold a new paren-class info rather than | 4683 ;; a matching-char info, in which case the two CDRs |
4684 ;; a matching-char info, in which case the two CDRs | 4684 ;; should match. |
4685 ;; should match. | 4685 (eq matching-paren (cdr (syntax-after (1- oldpos)))))) |
4686 (eq matching-paren (cdr (syntax-after (1- oldpos)))))) | 4686 (message "Mismatched parentheses")) |
4687 (message "Mismatched parentheses")) | 4687 ((not blinkpos) |
4688 ((not blinkpos) | 4688 (if (not blink-matching-paren-distance) |
4689 (if (not blink-matching-paren-distance) | 4689 (message "Unmatched parenthesis"))) |
4690 (message "Unmatched parenthesis"))) | 4690 ((pos-visible-in-window-p blinkpos) |
4691 ((pos-visible-in-window-p blinkpos) | 4691 ;; Matching open within window, temporarily move to blinkpos but only |
4692 ;; Matching open within window, temporarily move to blinkpos but only | 4692 ;; if `blink-matching-paren-on-screen' is non-nil. |
4693 ;; if `blink-matching-paren-on-screen' is non-nil. | 4693 (and blink-matching-paren-on-screen |
4694 (and blink-matching-paren-on-screen | 4694 (not show-paren-mode) |
4695 (not show-paren-mode) | 4695 (save-excursion |
4696 (save-excursion | 4696 (goto-char blinkpos) |
4697 (goto-char blinkpos) | 4697 (sit-for blink-matching-delay)))) |
4698 (sit-for blink-matching-delay)))) | 4698 (t |
4699 (t | 4699 (save-excursion |
4700 (save-excursion | 4700 (goto-char blinkpos) |
4701 (goto-char blinkpos) | 4701 (let ((open-paren-line-string |
4702 (setq open-paren-line-string | 4702 ;; Show what precedes the open in its line, if anything. |
4703 ;; Show what precedes the open in its line, if anything. | 4703 (cond |
4704 (if (save-excursion | 4704 ((save-excursion (skip-chars-backward " \t") (not (bolp))) |
4705 (skip-chars-backward " \t") | 4705 (buffer-substring (line-beginning-position) |
4706 (not (bolp))) | 4706 (1+ blinkpos))) |
4707 (buffer-substring (line-beginning-position) | 4707 ;; Show what follows the open in its line, if anything. |
4708 (1+ blinkpos)) | 4708 ((save-excursion |
4709 ;; Show what follows the open in its line, if anything. | 4709 (forward-char 1) |
4710 (if (save-excursion | 4710 (skip-chars-forward " \t") |
4711 (forward-char 1) | 4711 (not (eolp))) |
4712 (skip-chars-forward " \t") | 4712 (buffer-substring blinkpos |
4713 (not (eolp))) | 4713 (line-end-position))) |
4714 (buffer-substring blinkpos | 4714 ;; Otherwise show the previous nonblank line, |
4715 (line-end-position)) | 4715 ;; if there is one. |
4716 ;; Otherwise show the previous nonblank line, | 4716 ((save-excursion (skip-chars-backward "\n \t") (not (bobp))) |
4717 ;; if there is one. | 4717 (concat |
4718 (if (save-excursion | 4718 (buffer-substring (progn |
4719 (skip-chars-backward "\n \t") | 4719 (skip-chars-backward "\n \t") |
4720 (not (bobp))) | 4720 (line-beginning-position)) |
4721 (concat | 4721 (progn (end-of-line) |
4722 (buffer-substring (progn | 4722 (skip-chars-backward " \t") |
4723 (skip-chars-backward "\n \t") | 4723 (point))) |
4724 (line-beginning-position)) | 4724 ;; Replace the newline and other whitespace with `...'. |
4725 (progn (end-of-line) | 4725 "..." |
4726 (skip-chars-backward " \t") | 4726 (buffer-substring blinkpos (1+ blinkpos)))) |
4727 (point))) | 4727 ;; There is nothing to show except the char itself. |
4728 ;; Replace the newline and other whitespace with `...'. | 4728 (t (buffer-substring blinkpos (1+ blinkpos)))))) |
4729 "..." | 4729 (message "Matches %s" |
4730 (buffer-substring blinkpos (1+ blinkpos))) | 4730 (substring-no-properties open-paren-line-string))))))))) |
4731 ;; There is nothing to show except the char itself. | 4731 |
4732 (buffer-substring blinkpos (1+ blinkpos))))))) | 4732 ;; Turned off because it makes dbx bomb out. |
4733 (message "Matches %s" | |
4734 (substring-no-properties open-paren-line-string)))))))) | |
4735 | |
4736 ;Turned off because it makes dbx bomb out. | |
4737 (setq blink-paren-function 'blink-matching-open) | 4733 (setq blink-paren-function 'blink-matching-open) |
4738 | 4734 |
4739 ;; This executes C-g typed while Emacs is waiting for a command. | 4735 ;; This executes C-g typed while Emacs is waiting for a command. |
4740 ;; Quitting out of a program does not go through here; | 4736 ;; Quitting out of a program does not go through here; |
4741 ;; that happens in the QUIT macro at the C code level. | 4737 ;; that happens in the QUIT macro at the C code level. |