aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-04-11 23:44:06 +0000
committerStefan Monnier2002-04-11 23:44:06 +0000
commit41d22ee0a0810e2cce9e9a533c938a57670fece7 (patch)
tree1891990423b9a0eb41db30501d5e4193488bca44
parentbb424945f3c3355a275a15562f514a7771d66ee4 (diff)
downloademacs-41d22ee0a0810e2cce9e9a533c938a57670fece7.tar.gz
emacs-41d22ee0a0810e2cce9e9a533c938a57670fece7.zip
(line-move): Use memq rather than or.
(transpose-sexps): Don't presume as much of forward-sexp's behavior. (do-auto-fill): Use fill-move-to-break-point. (syntax-code-table): Remove.
-rw-r--r--lisp/simple.el175
1 files changed, 68 insertions, 107 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index eefac3fce0f..c8ce9932011 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2529,8 +2529,7 @@ Outline mode sets this."
2529 new line-end line-beg) 2529 new line-end line-beg)
2530 (unwind-protect 2530 (unwind-protect
2531 (progn 2531 (progn
2532 (if (not (or (eq last-command 'next-line) 2532 (if (not (memq last-command '(next-line previous-line)))
2533 (eq last-command 'previous-line)))
2534 (setq temporary-goal-column 2533 (setq temporary-goal-column
2535 (if (and track-eol (eolp) 2534 (if (and track-eol (eolp)
2536 ;; Don't count beg of empty line as end of line 2535 ;; Don't count beg of empty line as end of line
@@ -2743,6 +2742,7 @@ With prefix arg ARG, effect is to take word before or around point
2743and drag it forward past ARG other words (backward if ARG negative). 2742and drag it forward past ARG other words (backward if ARG negative).
2744If ARG is zero, the words around or after point and around or after mark 2743If ARG is zero, the words around or after point and around or after mark
2745are interchanged." 2744are interchanged."
2745 ;; FIXME: `foo a!nd bar' should transpose into `bar and foo'.
2746 (interactive "*p") 2746 (interactive "*p")
2747 (transpose-subr 'forward-word arg)) 2747 (transpose-subr 'forward-word arg))
2748 2748
@@ -2751,7 +2751,35 @@ are interchanged."
2751Does not work on a sexp that point is in the middle of 2751Does not work on a sexp that point is in the middle of
2752if it is a list or string." 2752if it is a list or string."
2753 (interactive "*p") 2753 (interactive "*p")
2754 (transpose-subr 'forward-sexp arg)) 2754 (transpose-subr
2755 (lambda (arg)
2756 ;; Here we should try to simulate the behavior of
2757 ;; (cons (progn (forward-sexp x) (point))
2758 ;; (progn (forward-sexp (- x)) (point)))
2759 ;; Except that we don't want to rely on the second forward-sexp
2760 ;; putting us back to where we want to be, since forward-sexp-function
2761 ;; might do funny things like infix-precedence.
2762 (if (if (> arg 0)
2763 (looking-at "\\sw\\|\\s_")
2764 (and (not (bobp))
2765 (save-excursion (forward-char -1) (looking-at "\\sw\\|\\s_"))))
2766 ;; Jumping over a symbol. We might be inside it, mind you.
2767 (progn (funcall (if (> arg 0)
2768 'skip-syntax-backward 'skip-syntax-forward)
2769 "w_")
2770 (cons (save-excursion (forward-sexp arg) (point)) (point)))
2771 ;; Otherwise, we're between sexps. Take a step back before jumping
2772 ;; to make sure we'll obey the same precedence no matter which direction
2773 ;; we're going.
2774 (funcall (if (> arg 0) 'skip-syntax-backward 'skip-syntax-forward) " .")
2775 (cons (save-excursion (forward-sexp arg) (point))
2776 (progn (while (or (forward-comment (if (> arg 0) 1 -1))
2777 (not (zerop (funcall (if (> arg 0)
2778 'skip-syntax-forward
2779 'skip-syntax-backward)
2780 ".")))))
2781 (point)))))
2782 arg 'special))
2755 2783
2756(defun transpose-lines (arg) 2784(defun transpose-lines (arg)
2757 "Exchange current line and previous line, leaving point after both. 2785 "Exchange current line and previous line, leaving point after both.
@@ -2940,9 +2968,7 @@ Setting this variable automatically makes it local to the current buffer.")
2940 ;; Determine where to split the line. 2968 ;; Determine where to split the line.
2941 (let* (after-prefix 2969 (let* (after-prefix
2942 (fill-point 2970 (fill-point
2943 (let ((opoint (point)) 2971 (let ((opoint (point)))
2944 bounce
2945 (first t))
2946 (save-excursion 2972 (save-excursion
2947 (beginning-of-line) 2973 (beginning-of-line)
2948 (setq after-prefix (point)) 2974 (setq after-prefix (point))
@@ -2950,87 +2976,50 @@ Setting this variable automatically makes it local to the current buffer.")
2950 (looking-at (regexp-quote fill-prefix)) 2976 (looking-at (regexp-quote fill-prefix))
2951 (setq after-prefix (match-end 0))) 2977 (setq after-prefix (match-end 0)))
2952 (move-to-column (1+ fc)) 2978 (move-to-column (1+ fc))
2953 ;; Move back to the point where we can break the line. 2979 (fill-move-to-break-point after-prefix)
2954 ;; We break the line between word or
2955 ;; after/before the character which has character
2956 ;; category `|'. We search space, \c| followed by
2957 ;; a character, or \c| following a character. If
2958 ;; not found, place the point at beginning of line.
2959 (while (or first
2960 (and (not (bobp))
2961 (not bounce)
2962 (fill-nobreak-p)))
2963 (setq first nil)
2964 (re-search-backward "[ \t]\\|\\c|.\\|.\\c|\\|^")
2965 ;; If we find nowhere on the line to break it,
2966 ;; break after one word. Set bounce to t
2967 ;; so we will not keep going in this while loop.
2968 (if (<= (point) after-prefix)
2969 (progn
2970 (goto-char after-prefix)
2971 (re-search-forward "[ \t]" opoint t)
2972 (setq bounce t))
2973 (if (looking-at "[ \t]")
2974 ;; Break the line at word boundary.
2975 (skip-chars-backward " \t")
2976 ;; Break the line after/before \c|.
2977 (forward-char 1))))
2978 (if enable-multibyte-characters
2979 ;; If we are going to break the line after or
2980 ;; before a non-ascii character, we may have
2981 ;; to run a special function for the charset
2982 ;; of the character to find the correct break
2983 ;; point.
2984 (if (not (and (eq (charset-after (1- (point))) 'ascii)
2985 (eq (charset-after (point)) 'ascii)))
2986 (fill-find-break-point after-prefix)))
2987
2988 ;; Let fill-point be set to the place where we end up.
2989 ;; But move back before any whitespace here.
2990 (skip-chars-backward " \t")
2991 (point))))) 2980 (point)))))
2992 2981
2993 ;; See whether the place we found is any good. 2982 ;; See whether the place we found is any good.
2994 (if (save-excursion 2983 (if (save-excursion
2995 (goto-char fill-point) 2984 (goto-char fill-point)
2996 (and (not (bolp)) 2985 (or (bolp)
2997 ;; There is no use breaking at end of line. 2986 ;; There is no use breaking at end of line.
2998 (not (save-excursion (skip-chars-forward " ") (eolp))) 2987 (save-excursion (skip-chars-forward " ") (eolp))
2999 ;; It is futile to split at the end of the prefix 2988 ;; It is futile to split at the end of the prefix
3000 ;; since we would just insert the prefix again. 2989 ;; since we would just insert the prefix again.
3001 (not (and after-prefix (<= (point) after-prefix))) 2990 (and after-prefix (<= (point) after-prefix))
3002 ;; Don't split right after a comment starter 2991 ;; Don't split right after a comment starter
3003 ;; since we would just make another comment starter. 2992 ;; since we would just make another comment starter.
3004 (not (and comment-start-skip 2993 (and comment-start-skip
3005 (let ((limit (point))) 2994 (let ((limit (point)))
3006 (beginning-of-line) 2995 (beginning-of-line)
3007 (and (re-search-forward comment-start-skip 2996 (and (re-search-forward comment-start-skip
3008 limit t) 2997 limit t)
3009 (eq (point) limit))))))) 2998 (eq (point) limit))))))
3010 ;; Ok, we have a useful place to break the line. Do it. 2999 ;; No good place to break => stop trying.
3011 (let ((prev-column (current-column))) 3000 (setq give-up t)
3012 ;; If point is at the fill-point, do not `save-excursion'. 3001 ;; Ok, we have a useful place to break the line. Do it.
3013 ;; Otherwise, if a comment prefix or fill-prefix is inserted, 3002 (let ((prev-column (current-column)))
3014 ;; point will end up before it rather than after it. 3003 ;; If point is at the fill-point, do not `save-excursion'.
3015 (if (save-excursion 3004 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
3016 (skip-chars-backward " \t") 3005 ;; point will end up before it rather than after it.
3017 (= (point) fill-point)) 3006 (if (save-excursion
3018 (funcall comment-line-break-function t) 3007 (skip-chars-backward " \t")
3008 (= (point) fill-point))
3009 (funcall comment-line-break-function t)
3010 (save-excursion
3011 (goto-char fill-point)
3012 (funcall comment-line-break-function t)))
3013 ;; Now do justification, if required
3014 (if (not (eq justify 'left))
3019 (save-excursion 3015 (save-excursion
3020 (goto-char fill-point)
3021 (funcall comment-line-break-function t)))
3022 ;; Now do justification, if required
3023 (if (not (eq justify 'left))
3024 (save-excursion
3025 (end-of-line 0) 3016 (end-of-line 0)
3026 (justify-current-line justify nil t))) 3017 (justify-current-line justify nil t)))
3027 ;; If making the new line didn't reduce the hpos of 3018 ;; If making the new line didn't reduce the hpos of
3028 ;; the end of the line, then give up now; 3019 ;; the end of the line, then give up now;
3029 ;; trying again will not help. 3020 ;; trying again will not help.
3030 (if (>= (current-column) prev-column) 3021 (if (>= (current-column) prev-column)
3031 (setq give-up t))) 3022 (setq give-up t))))))
3032 ;; No good place to break => stop trying.
3033 (setq give-up t))))
3034 ;; Justify last line. 3023 ;; Justify last line.
3035 (justify-current-line justify t t) 3024 (justify-current-line justify t t)
3036 t))) 3025 t)))
@@ -4079,34 +4068,6 @@ the front of the list of recently selected ones."
4079(define-key ctl-x-4-map "c" 'clone-indirect-buffer-other-window) 4068(define-key ctl-x-4-map "c" 'clone-indirect-buffer-other-window)
4080 4069
4081 4070
4082;;; Syntax stuff.
4083
4084(defconst syntax-code-table
4085 '((?\ 0 "whitespace")
4086 (?- 0 "whitespace")
4087 (?. 1 "punctuation")
4088 (?w 2 "word")
4089 (?_ 3 "symbol")
4090 (?\( 4 "open parenthesis")
4091 (?\) 5 "close parenthesis")
4092 (?\' 6 "expression prefix")
4093 (?\" 7 "string quote")
4094 (?$ 8 "paired delimiter")
4095 (?\\ 9 "escape")
4096 (?/ 10 "character quote")
4097 (?< 11 "comment start")
4098 (?> 12 "comment end")
4099 (?@ 13 "inherit")
4100 (nil 14 "comment fence")
4101 (nil 15 "string fence"))
4102 "Alist of forms (CHAR CODE DESCRIPTION) mapping characters to syntax info.
4103CHAR is a character that is allowed as first char in the string
4104specifying the syntax when calling `modify-syntax-entry'. CODE is the
4105corresponing syntax code as it is stored in a syntax cell, and
4106can be used as value of a `syntax-table' property.
4107DESCRIPTION is the descriptive string for the syntax.")
4108
4109
4110;;; Handling of Backspace and Delete keys. 4071;;; Handling of Backspace and Delete keys.
4111 4072
4112(defcustom normal-erase-is-backspace nil 4073(defcustom normal-erase-is-backspace nil