comparison lisp/simple.el @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents 74fd4e045ea6
children b8cc9ab3f761
comparison
equal deleted inserted replaced
403:9f011ab08d48 404:2f8bb876ab1d
1 ;;; simple.el --- basic editing commands for XEmacs 1 ;;; simple.el --- basic editing commands for XEmacs
2 2
3 ;; Copyright (C) 1985-7, 1993-5, 1997 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985-7, 1993-5, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp. 4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
5 ;; Copyright (C) 2000 Ben Wing.
5 6
6 ;; Maintainer: XEmacs Development Team 7 ;; Maintainer: XEmacs Development Team
7 ;; Keywords: lisp, extensions, internal, dumped 8 ;; Keywords: lisp, extensions, internal, dumped
8 9
9 ;; This file is part of XEmacs. 10 ;; This file is part of XEmacs.
1085 (interactive "_p") 1086 (interactive "_p")
1086 (forward-line (- arg)) 1087 (forward-line (- arg))
1087 (skip-chars-forward " \t")) 1088 (skip-chars-forward " \t"))
1088 1089
1089 (defcustom kill-whole-line nil 1090 (defcustom kill-whole-line nil
1090 "*If non-nil, `kill-line' with no arg at beg of line kills the whole line." 1091 "*Control when and whether `kill-line' removes entire lines.
1091 :type 'boolean 1092 Note: This only applies when `kill-line' is called interactively;
1093 otherwise, it behaves \"historically\".
1094
1095 If `always', `kill-line' with no arg always kills the whole line,
1096 wherever point is in the line. (If you want to just kill to the end
1097 of the line, use \\[historical-kill-line].)
1098
1099 If not `always' but non-nil, `kill-line' with no arg kills the whole
1100 line if point is at the beginning, and otherwise behaves historically.
1101
1102 If nil, `kill-line' behaves historically."
1103 :type '(radio (const :tag "Kill to end of line" nil)
1104 (const :tag "Kill whole line" always)
1105 (const
1106 :tag "Kill whole line at beginning, otherwise end of line" t))
1092 :group 'killing) 1107 :group 'killing)
1093 1108
1109 (defun historical-kill-line (&optional arg)
1110 "Same as `kill-line' but ignores value of `kill-whole-line'."
1111 (interactive "*P")
1112 (let ((kill-whole-line nil))
1113 (if (interactive-p)
1114 (call-interactively 'kill-line)
1115 (kill-line arg))))
1116
1094 (defun kill-line (&optional arg) 1117 (defun kill-line (&optional arg)
1095 "Kill the rest of the current line; if no nonblanks there, kill thru newline. 1118 "Kill the rest of the current line, or the entire line.
1119 If no nonblanks there, kill thru newline.
1120 If called interactively, may kill the entire line; see `kill-whole-line'.
1121 when given no argument at the beginning of a line.
1096 With prefix argument, kill that many lines from point. 1122 With prefix argument, kill that many lines from point.
1097 Negative arguments kill lines backward. 1123 Negative arguments kill lines backward.
1098 1124
1099 When calling from a program, nil means \"no arg\", 1125 When calling from a program, nil means \"no arg\",
1100 a number counts as a prefix arg. 1126 a number counts as a prefix arg."
1101
1102 If `kill-whole-line' is non-nil, then kill the whole line
1103 when given no argument at the beginning of a line."
1104 (interactive "*P") 1127 (interactive "*P")
1105 (kill-region (point) 1128 (kill-region (if (and (interactive-p)
1129 (not arg)
1130 (eq kill-whole-line 'always))
1131 (save-excursion
1132 (beginning-of-line)
1133 (point))
1134 (point))
1106 ;; Don't shift point before doing the delete; that way, 1135 ;; Don't shift point before doing the delete; that way,
1107 ;; undo will record the right position of point. 1136 ;; undo will record the right position of point.
1108 ;; FSF 1137 ;; FSF
1109 ; ;; It is better to move point to the other end of the kill 1138 ; ;; It is better to move point to the other end of the kill
1110 ; ;; before killing. That way, in a read-only buffer, point 1139 ; ;; before killing. That way, in a read-only buffer, point
1115 (save-excursion 1144 (save-excursion
1116 (if arg 1145 (if arg
1117 (forward-line (prefix-numeric-value arg)) 1146 (forward-line (prefix-numeric-value arg))
1118 (if (eobp) 1147 (if (eobp)
1119 (signal 'end-of-buffer nil)) 1148 (signal 'end-of-buffer nil))
1120 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp))) 1149 (if (or (looking-at "[ \t]*$")
1150 (and (interactive-p)
1151 (or (eq kill-whole-line 'always)
1152 (and kill-whole-line (bolp)))))
1121 (forward-line 1) 1153 (forward-line 1)
1122 (end-of-line))) 1154 (end-of-line)))
1123 (point)))) 1155 (point))))
1124 1156
1125 ;; XEmacs 1157 ;; XEmacs
1152 ;;; `kill-hooks' seems not sufficient because 1184 ;;; `kill-hooks' seems not sufficient because
1153 ;;; `interprogram-cut-function' requires more variable about to rotate 1185 ;;; `interprogram-cut-function' requires more variable about to rotate
1154 ;;; the cut buffers. I'm afraid to change interface of `kill-hooks', 1186 ;;; the cut buffers. I'm afraid to change interface of `kill-hooks',
1155 ;;; so I add it. (1997-11-03 by MORIOKA Tomohiko) 1187 ;;; so I add it. (1997-11-03 by MORIOKA Tomohiko)
1156 1188
1157 (defvar interprogram-cut-function nil 1189 (defcustom interprogram-cut-function 'own-clipboard
1158 "Function to call to make a killed region available to other programs. 1190 "Function to call to make a killed region available to other programs.
1159 1191
1160 Most window systems provide some sort of facility for cutting and 1192 Most window systems provide some sort of facility for cutting and
1161 pasting text between the windows of different programs. 1193 pasting text between the windows of different programs.
1162 This variable holds a function that Emacs calls whenever text 1194 This variable holds a function that Emacs calls whenever text
1165 1197
1166 The function takes one or two arguments. 1198 The function takes one or two arguments.
1167 The first argument, TEXT, is a string containing 1199 The first argument, TEXT, is a string containing
1168 the text which should be made available. 1200 the text which should be made available.
1169 The second, PUSH, if non-nil means this is a \"new\" kill; 1201 The second, PUSH, if non-nil means this is a \"new\" kill;
1170 nil means appending to an \"old\" kill.") 1202 nil means appending to an \"old\" kill."
1171 1203 :type '(radio (function-item :tag "Send to Clipboard"
1172 (defvar interprogram-paste-function nil 1204 :format "%t\n"
1205 own-clipboard)
1206 (const :tag "None" nil)
1207 (function :tag "Other"))
1208 :group 'killing)
1209
1210 (defcustom interprogram-paste-function 'get-clipboard
1173 "Function to call to get text cut from other programs. 1211 "Function to call to get text cut from other programs.
1174 1212
1175 Most window systems provide some sort of facility for cutting and 1213 Most window systems provide some sort of facility for cutting and
1176 pasting text between the windows of different programs. 1214 pasting text between the windows of different programs.
1177 This variable holds a function that Emacs calls to obtain 1215 This variable holds a function that Emacs calls to obtain
1185 Note that the function should return a string only if a program other 1223 Note that the function should return a string only if a program other
1186 than Emacs has provided a string for pasting; if Emacs provided the 1224 than Emacs has provided a string for pasting; if Emacs provided the
1187 most recent string, the function should return nil. If it is 1225 most recent string, the function should return nil. If it is
1188 difficult to tell whether Emacs or some other program provided the 1226 difficult to tell whether Emacs or some other program provided the
1189 current string, it is probably good enough to return nil if the string 1227 current string, it is probably good enough to return nil if the string
1190 is equal (according to `string=') to the last text Emacs provided.") 1228 is equal (according to `string=') to the last text Emacs provided."
1229 :type '(radio (function-item :tag "Get from Clipboard"
1230 :format "%t\n"
1231 get-clipboard)
1232 (const :tag "None" nil)
1233 (function :tag "Other"))
1234 :group 'killing)
1191 1235
1192 1236
1193 ;;;; The kill ring data structure. 1237 ;;;; The kill ring data structure.
1194 1238
1195 (defvar kill-ring nil 1239 (defvar kill-ring nil
1802 This behavior used to be the default, and is still default in FSF Emacs. 1846 This behavior used to be the default, and is still default in FSF Emacs.
1803 We think it is an unnecessary and unwanted side-effect." 1847 We think it is an unnecessary and unwanted side-effect."
1804 :type 'boolean 1848 :type 'boolean
1805 :group 'editing-basics) 1849 :group 'editing-basics)
1806 1850
1851 (defcustom shifted-motion-keys-select-region t
1852 "*If non-nil, shifted motion keys select text, like in MS Windows.
1853 See also `unshifted-motion-keys-deselect-region'."
1854 :type 'boolean
1855 :group 'editing-basics)
1856
1857 (defcustom unshifted-motion-keys-deselect-region t
1858 "*If non-nil, unshifted motion keys deselect a shifted-motion region.
1859 This only occurs after a region has been selected using shifted motion keys
1860 (not when using the traditional set-mark-then-move method), and has no effect
1861 if `shifted-motion-keys-select-region' is nil."
1862 :type 'boolean
1863 :group 'editing-basics)
1864
1865 (defun handle-pre-motion-command-current-command-is-motion ()
1866 (and (key-press-event-p last-input-event)
1867 (memq (event-key last-input-event)
1868 '(left right up down home end prior next
1869 kp-left kp-right kp-up kp-down
1870 kp-home kp-end kp-prior kp-next))))
1871
1872 (defun handle-pre-motion-command ()
1873 (if
1874 (and
1875 (handle-pre-motion-command-current-command-is-motion)
1876 zmacs-regions
1877 shifted-motion-keys-select-region
1878 (not (region-active-p))
1879 (memq 'shift (event-modifiers last-input-event)))
1880 (push-mark nil nil t)))
1881
1882 (defun handle-post-motion-command ()
1883 (if
1884 (and
1885 (handle-pre-motion-command-current-command-is-motion)
1886 zmacs-regions
1887 (region-active-p))
1888 (cond ((memq 'shift (event-modifiers last-input-event))
1889 (if shifted-motion-keys-select-region
1890 (putf this-command-properties 'shifted-motion-command t))
1891 (setq zmacs-region-stays t))
1892 ((and (getf last-command-properties 'shifted-motion-command)
1893 unshifted-motion-keys-deselect-region)
1894 (setq zmacs-region-stays nil))
1895 (t
1896 (setq zmacs-region-stays t)))))
1897
1807 (defun forward-char-command (&optional arg buffer) 1898 (defun forward-char-command (&optional arg buffer)
1808 "Move point right ARG characters (left if ARG negative) in BUFFER. 1899 "Move point right ARG characters (left if ARG negative) in BUFFER.
1809 On attempt to pass end of buffer, stop and signal `end-of-buffer'. 1900 On attempt to pass end of buffer, stop and signal `end-of-buffer'.
1810 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'. 1901 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'.
1811 Error signaling is suppressed if `signal-error-on-buffer-boundary' 1902 Error signaling is suppressed if `signal-error-on-buffer-boundary'
1887 in `goal-column', which is nil when there is none. 1978 in `goal-column', which is nil when there is none.
1888 1979
1889 If you are thinking of using this in a Lisp program, consider 1980 If you are thinking of using this in a Lisp program, consider
1890 using `forward-line' instead. It is usually easier to use 1981 using `forward-line' instead. It is usually easier to use
1891 and more reliable (no dependence on goal column, etc.)." 1982 and more reliable (no dependence on goal column, etc.)."
1892 (interactive "_p") ; XEmacs 1983 (interactive "_p")
1893 (if (and next-line-add-newlines (= arg 1)) 1984 (if (and next-line-add-newlines (= arg 1))
1894 (let ((opoint (point))) 1985 (let ((opoint (point)))
1895 (end-of-line) 1986 (end-of-line)
1896 (if (eobp) 1987 (if (eobp)
1897 (newline 1) 1988 (newline 1)
1918 Then it does not try to move vertically. 2009 Then it does not try to move vertically.
1919 2010
1920 If you are thinking of using this in a Lisp program, consider using 2011 If you are thinking of using this in a Lisp program, consider using
1921 `forward-line' with a negative argument instead. It is usually easier 2012 `forward-line' with a negative argument instead. It is usually easier
1922 to use and more reliable (no dependence on goal column, etc.)." 2013 to use and more reliable (no dependence on goal column, etc.)."
1923 (interactive "_p") ; XEmacs 2014 (interactive "_p")
1924 (if (interactive-p) 2015 (if (interactive-p)
1925 (condition-case nil 2016 (condition-case nil
1926 (line-move (- arg)) 2017 (line-move (- arg))
1927 ((beginning-of-buffer end-of-buffer) 2018 ((beginning-of-buffer end-of-buffer)
1928 (when signal-error-on-buffer-boundary ; XEmacs 2019 (when signal-error-on-buffer-boundary ; XEmacs
1929 (ding nil 'buffer-bound)))) 2020 (ding nil 'buffer-bound))))
1930 (line-move (- arg))) 2021 (line-move (- arg)))
1931 nil) 2022 nil)
2023
2024 (defcustom block-movement-size 6
2025 "*Number of lines that \"block movement\" commands (\\[forward-block-of-lines], \\[backward-block-of-lines]) move by."
2026 :type 'integer
2027 :group 'editing-basics)
2028
2029 (defun backward-block-of-lines ()
2030 "Move backward by one \"block\" of lines.
2031 The number of lines that make up a block is controlled by
2032 `block-movement-size', which defaults to 6."
2033 (interactive "_")
2034 (forward-line (- block-movement-size)))
2035
2036 (defun forward-block-of-lines ()
2037 "Move forward by one \"block\" of lines.
2038 The number of lines that make up a block is controlled by
2039 `block-movement-size', which defaults to 6."
2040 (interactive "_")
2041 (forward-line block-movement-size))
1932 2042
1933 (defcustom track-eol nil 2043 (defcustom track-eol nil
1934 "*Non-nil means vertical motion starting at end of line keeps to ends of lines. 2044 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
1935 This means moving to the end of each line moved onto. 2045 This means moving to the end of each line moved onto.
1936 The beginning of a blank line does not count as the end of a line." 2046 The beginning of a blank line does not count as the end of a line."
3416 (interactive "p") 3526 (interactive "p")
3417 (if (region-active-p) 3527 (if (region-active-p)
3418 (downcase-region (region-beginning) (region-end)) 3528 (downcase-region (region-beginning) (region-end))
3419 (downcase-word arg))) 3529 (downcase-word arg)))
3420 3530
3531 ;; #### not localized
3532 (defvar uncapitalized-title-words
3533 '("the" "a" "an" "in" "of" "for" "to" "and" "but" "at" "on" "as" "by"))
3534
3535 (defvar uncapitalized-title-word-regexp
3536 (concat "[ \t]*\\(" (mapconcat #'identity uncapitalized-title-words "\\|")
3537 "\\)\\>"))
3538
3539 (defun capitalize-string-as-title (string)
3540 "Capitalize the words in the string, except for small words (as in titles).
3541 The words not capitalized are specified in `uncapitalized-title-words'."
3542 (let ((buffer (get-buffer-create " *capitalize-string-as-title*")))
3543 (unwind-protect
3544 (progn
3545 (insert-string string buffer)
3546 (capitalize-region-as-title 1 (point-max buffer) buffer)
3547 (buffer-string buffer))
3548 (kill-buffer buffer))))
3549
3550 (defun capitalize-region-as-title (b e &optional buffer)
3551 "Capitalize the words in the region, except for small words (as in titles).
3552 The words not capitalized are specified in `uncapitalized-title-words'."
3553 (interactive "r")
3554 (save-excursion
3555 (and buffer
3556 (set-buffer buffer))
3557 (save-restriction
3558 (narrow-to-region b e)
3559 (goto-char (point-min))
3560 (let ((first t))
3561 (while (< (point) (point-max))
3562 (if (or first
3563 (not (looking-at uncapitalized-title-word-regexp)))
3564 (capitalize-word 1)
3565 (forward-word 1))
3566 (setq first nil))))))
3567
3421 ;; Most of the zmacs code is now in elisp. The only thing left in C 3568 ;; Most of the zmacs code is now in elisp. The only thing left in C
3422 ;; are the variables zmacs-regions, zmacs-region-active-p and 3569 ;; are the variables zmacs-regions, zmacs-region-active-p and
3423 ;; zmacs-region-stays plus the function zmacs_update_region which 3570 ;; zmacs-region-stays plus the function zmacs_update_region which
3424 ;; simply calls the lisp level zmacs-update-region. It must remain 3571 ;; simply calls the lisp level zmacs-update-region. It must remain
3425 ;; for convenience, since it is called by core C code. 3572 ;; for convenience, since it is called by core C code.
4095 (defun emacs-name () 4242 (defun emacs-name ()
4096 "Return the printable name of this instance of Emacs." 4243 "Return the printable name of this instance of Emacs."
4097 (cond ((featurep 'infodock) "InfoDock") 4244 (cond ((featurep 'infodock) "InfoDock")
4098 ((featurep 'xemacs) "XEmacs") 4245 ((featurep 'xemacs) "XEmacs")
4099 (t "Emacs"))) 4246 (t "Emacs")))
4100 4247
4101 ;;; simple.el ends here 4248 ;;; simple.el ends here