comparison lisp/simple.el @ 44505:76f93b741944

(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.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 11 Apr 2002 23:44:06 +0000
parents 4bcede390f6f
children 2776503d098e
comparison
equal deleted inserted replaced
44504:483f757c5f72 44505:76f93b741944
2527 (let ((inhibit-point-motion-hooks t) 2527 (let ((inhibit-point-motion-hooks t)
2528 (opoint (point)) 2528 (opoint (point))
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
2537 ;; unless we just did explicit end-of-line. 2536 ;; unless we just did explicit end-of-line.
2538 (or (not (bolp)) (eq last-command 'end-of-line))) 2537 (or (not (bolp)) (eq last-command 'end-of-line)))
2741 "Interchange words around point, leaving point at end of them. 2740 "Interchange words around point, leaving point at end of them.
2742 With prefix arg ARG, effect is to take word before or around point 2741 With prefix arg ARG, effect is to take word before or around point
2743 and drag it forward past ARG other words (backward if ARG negative). 2742 and drag it forward past ARG other words (backward if ARG negative).
2744 If ARG is zero, the words around or after point and around or after mark 2743 If ARG is zero, the words around or after point and around or after mark
2745 are interchanged." 2744 are 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
2749 (defun transpose-sexps (arg) 2749 (defun transpose-sexps (arg)
2750 "Like \\[transpose-words] but applies to sexps. 2750 "Like \\[transpose-words] but applies to sexps.
2751 Does not work on a sexp that point is in the middle of 2751 Does not work on a sexp that point is in the middle of
2752 if it is a list or string." 2752 if 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.
2758 With argument ARG, takes previous line and moves it past ARG lines. 2786 With argument ARG, takes previous line and moves it past ARG lines.
2759 With argument 0, interchanges line point is in with line mark is in." 2787 With argument 0, interchanges line point is in with line mark is in."
2938 2966
2939 (while (and (not give-up) (> (current-column) fc)) 2967 (while (and (not give-up) (> (current-column) fc))
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))
2949 (and fill-prefix 2975 (and fill-prefix
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)))
3037 3026
3038 (defvar normal-auto-fill-function 'do-auto-fill 3027 (defvar normal-auto-fill-function 'do-auto-fill
4077 (clone-indirect-buffer nil t norecord))) 4066 (clone-indirect-buffer nil t norecord)))
4078 4067
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.
4103 CHAR is a character that is allowed as first char in the string
4104 specifying the syntax when calling `modify-syntax-entry'. CODE is the
4105 corresponing syntax code as it is stored in a syntax cell, and
4106 can be used as value of a `syntax-table' property.
4107 DESCRIPTION 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
4113 "If non-nil, Delete key deletes forward and Backspace key deletes backward. 4074 "If non-nil, Delete key deletes forward and Backspace key deletes backward.
4114 4075