;;; simple.el --- basic editing commands for Emacs
;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
;; Free Software Foundation, Inc.
;; Maintainer: FSF
;;; Code:
-(eval-when-compile
- (autoload 'widget-convert "wid-edit")
- (autoload 'shell-mode "shell"))
+(declare-function widget-convert "wid-edit" (type &rest args))
+(declare-function shell-mode "shell" ())
(defvar compilation-current-error)
(defun goto-line (arg &optional buffer)
"Goto line ARG, counting from line 1 at beginning of buffer.
-Normally, move point in the current buffer.
-With just \\[universal-argument] as argument, move point in the most recently
-displayed other buffer, and switch to it. When called from Lisp code,
-the optional argument BUFFER specifies a buffer to switch to.
+Normally, move point in the current buffer, and leave mark at previous
+position. With just \\[universal-argument] as argument, move point
+in the most recently displayed other buffer, and switch to it.
+When called from Lisp code, the optional argument BUFFER specifies
+a buffer to switch to.
If there's a number in the buffer at point, it is the default for ARG."
(interactive
(let ((window (get-buffer-window buffer)))
(if window (select-window window)
(switch-to-buffer-other-window buffer))))
+ ;; Leave mark at previous position
+ (or (and transient-mark-mode mark-active)
+ (push-mark))
;; Move to the specified line number in that buffer.
(save-restriction
(widen)
(if (or (not coding)
(eq (coding-system-type coding) t))
(setq coding default-buffer-file-coding-system))
- (if (not (char-valid-p char))
+ (if (eq (char-charset char) 'eight-bit)
(setq encoding-msg
- (format "(%d, #o%o, #x%x, invalid)" char char char))
+ (format "(%d, #o%o, #x%x, raw-byte)" char char char))
;; Check if the character is displayed with some `display'
;; text property. In that case, set under-display to the
;; buffer substring covered by that property.
(defvar minibuffer-history nil
"Default minibuffer history list.
This is used for all minibuffer input
-except when an alternate history list is specified.")
+except when an alternate history list is specified.
+
+Maximum length of the history list is determined by the value
+of `history-length', which see.")
(defvar minibuffer-history-sexp-flag nil
"Control whether history list elements are expressions or strings.
If the value of this variable equals current minibuffer depth,
(delete-auto-save-file-if-necessary recent-save))
;; Display a message announcing success.
(if message
- (message message))))
+ (message "%s" message))))
(defun buffer-disable-undo (&optional buffer)
"Make BUFFER stop keeping undo information.
t))
\f
(defvar shell-command-history nil
- "History list for some commands that read shell commands.")
+ "History list for some commands that read shell commands.
+
+Maximum length of the history list is determined by the value
+of `history-length', which see.")
(defvar shell-command-switch "-c"
"Switch used to have the shell execute its command line argument.")
is run interactively. A value of nil means that output to stderr and
stdout will be intermixed in the output stream.")
+(defun minibuffer-complete-shell-command ()
+ "Dynamically complete shell command at point."
+ (interactive)
+ (require 'shell)
+ (run-hook-with-args-until-success 'shell-dynamic-complete-functions))
+
+(defvar minibuffer-local-shell-command-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map minibuffer-local-map)
+ (define-key map "\t" 'minibuffer-complete-shell-command)
+ map)
+ "Keymap used for completiing shell commands in minibufffer.")
+
+(defun read-shell-command (prompt &optional initial-contents hist &rest args)
+ "Read a shell command from the minibuffer.
+The arguments are the same as the ones of `read-from-minibuffer',
+except READ and KEYMAP are missing and HIST defaults
+to `shell-command-history'."
+ (apply 'read-from-minibuffer prompt initial-contents
+ (or keymap minibuffer-local-shell-command-map)
+ nil
+ (or hist 'shell-command-history)
+ args))
+
(defun shell-command (command &optional output-buffer error-buffer)
"Execute string COMMAND in inferior shell; display output, if any.
With prefix argument, insert the COMMAND's output at point.
In an interactive call, the variable `shell-command-default-error-buffer'
specifies the value of ERROR-BUFFER."
- (interactive (list (read-from-minibuffer "Shell command: "
- nil nil nil 'shell-command-history)
+ (interactive (list (read-shell-command "Shell command: ")
current-prefix-arg
shell-command-default-error-buffer))
;; Look for a handler in case default-directory is a remote file name.
;; Do this before calling region-beginning
;; and region-end, in case subprocess output
;; relocates them while we are in the minibuffer.
- (setq string (read-from-minibuffer "Shell command on region: "
- nil nil nil
- 'shell-command-history))
+ (setq string (read-shell-command "Shell command on region: "))
;; call-interactively recognizes region-beginning and
;; region-end specially, leaving them in the history.
(list (region-beginning) (region-end)
(equal yank-handler (get-text-property 0 'yank-handler cur)))
yank-handler)))
+(defcustom yank-pop-change-selection nil
+ "If non-nil, rotating the kill ring changes the window system selection."
+ :type 'boolean
+ :group 'killing
+ :version "23.1")
+
(defun current-kill (n &optional do-not-move)
"Rotate the yanking point by N places, and then return that kill.
If N is zero, `interprogram-paste-function' is set, and calling it returns a
string or list of strings, then that string (or list) is added to the front
of the kill ring and the string (or first string in the list) is returned as
-the latest kill. If optional arg DO-NOT-MOVE is non-nil, then don't
-actually move the yanking point; just return the Nth kill forward."
+the latest kill.
+
+If N is not zero, and if `yank-pop-change-selection' is
+non-nil, use `interprogram-cut-function' to transfer the
+kill at the new yank point into the window system selection.
+
+If optional arg DO-NOT-MOVE is non-nil, then don't actually
+move the yanking point; just return the Nth kill forward."
+
(let ((interprogram-paste (and (= n 0)
interprogram-paste-function
(funcall interprogram-paste-function))))
(nthcdr (mod (- n (length kill-ring-yank-pointer))
(length kill-ring))
kill-ring)))
- (or do-not-move
- (setq kill-ring-yank-pointer ARGth-kill-element))
+ (unless do-not-move
+ (setq kill-ring-yank-pointer ARGth-kill-element)
+ (when (and yank-pop-change-selection
+ (> n 0)
+ interprogram-cut-function)
+ (funcall interprogram-cut-function (car ARGth-kill-element))))
(car ARGth-kill-element)))))
(setq mark-active nil)
(run-hooks 'deactivate-mark-hook))))
+(defcustom select-active-regions nil
+ "If non-nil, an active region automatically becomes the window selection."
+ :type 'boolean
+ :group 'killing
+ :version "23.1")
+
(defun set-mark (pos)
"Set this buffer's mark to POS. Don't use this function!
That is to say, don't use this function unless you want
(progn
(setq mark-active t)
(run-hooks 'activate-mark-hook)
+ (and select-active-regions
+ (x-set-selection
+ nil (buffer-substring (region-beginning) (region-end))))
(set-marker (mark-marker) pos (current-buffer)))
;; Normally we never clear mark-active except in Transient Mark mode.
;; But when we actually clear out the mark value too,
(run-hooks 'deactivate-mark-hook)
(set-marker (mark-marker) nil)))
+(defcustom use-empty-active-region nil
+ "If non-nil, an active region takes control even if empty.
+This applies to certain commands which, in Transient Mark mode,
+apply to the active region if there is one. If the setting is t,
+these commands apply to an empty active region if there is one.
+If the setting is nil, these commands treat an empty active
+region as if it were not active."
+ :type 'boolean
+ :version "23.1"
+ :group 'editing-basics)
+
+(defun use-region-p ()
+ "Return t if certain commands should apply to the region.
+Certain commands normally apply to text near point,
+but in Transient Mark mode when the mark is active they apply
+to the region instead. Such commands should use this subroutine to
+test whether to do that.
+
+This function also obeys `use-empty-active-region'."
+ (and transient-mark-mode mark-active
+ (or use-empty-active-region (> (region-end) (region-beginning)))))
+
+(defun region-active-p ()
+ "Return t if Transient Mark mode is enabled and the mark is active.
+This is NOT the best function to use to test whether a command should
+operate on the region instead of the usual behavior -- for that,
+use `use-region-p'."
+ (and transient-mark-mode mark-active))
+
(defvar mark-ring nil
"The list of former marks of the current buffer, most recent first.")
(make-variable-buffer-local 'mark-ring)
old mark position on local mark ring. Also push the old mark on
global mark ring, if the previous mark was set in another buffer.
-Immediately repeating this command activates `transient-mark-mode' temporarily.
+When Transient Mark Mode is off, immediately repeating this
+command activates `transient-mark-mode' temporarily.
With prefix argument \(e.g., \\[universal-argument] \\[set-mark-command]\), \
jump to the mark, and set the mark from
mark-active (null transient-mark-mode))
(setq transient-mark-mode 'lambda)
(message "Transient-mark-mode temporarily enabled"))
+ ((and (eq last-command 'set-mark-command)
+ transient-mark-mode)
+ (deactivate-mark))
(t
(push-mark-command nil))))
Invoke \\[apropos-documentation] and type \"transient\" or
\"mark.*active\" at the prompt, to see the documentation of
commands which are sensitive to the Transient Mark mode."
- :global t :group 'editing-basics)
+ :global t
+;;; :init-value (not noninteractive)
+ :group 'editing-basics)
(defvar widen-automatically t
"Non-nil means it is ok for commands to call `widen' when they want to.
string)
:group 'fill)
(make-variable-buffer-local 'fill-prefix)
-;;;###autoload(put 'fill-prefix 'safe-local-variable 'string-or-null-p)
+(put 'fill-prefix 'safe-local-variable 'string-or-null-p)
(defcustom auto-fill-inhibit-regexp nil
"*Regexp to match lines which should not be auto-filled."
(princ "." t))
(defvaralias 'indicate-unused-lines 'indicate-empty-lines)
-(defvaralias 'default-indicate-unused-lines 'default-indicate-empty-lines)
(defun toggle-truncate-lines (&optional arg)
"Toggle whether to fold or truncate long lines for the current buffer.
'switch-to-buffer-other-frame yank-action send-actions))
\f
(defvar set-variable-value-history nil
- "History of values entered with `set-variable'.")
+ "History of values entered with `set-variable'.
+
+Maximum length of the history list is determined by the value
+of `history-length', which see.")
(defun set-variable (variable value &optional make-local)
"Set VARIABLE to VALUE. VALUE is a Lisp object.
Type \\<completion-list-mode-map>\\[choose-completion] in the completion list\
to select the completion near point.
Use \\<completion-list-mode-map>\\[mouse-choose-completion] to select one\
- with the mouse."
+ with the mouse.
+
+\\{completion-list-mode-map}"
+
(interactive)
(kill-all-local-variables)
(use-local-map completion-list-mode-map)
(defvar clone-buffer-hook nil
"Normal hook to run in the new buffer at the end of `clone-buffer'.")
+(defvar clone-indirect-buffer-hook nil
+ "Normal hook to run in the new buffer at the end of `clone-indirect-buffer'.")
+
(defun clone-process (process &optional newname)
"Create a twin copy of PROCESS.
If NEWNAME is nil, it defaults to PROCESS' name;
(setq newname (substring newname 0 (match-beginning 0))))
(let* ((name (generate-new-buffer-name newname))
(buffer (make-indirect-buffer (current-buffer) name t)))
+ (with-current-buffer buffer
+ (run-hooks 'clone-indirect-buffer-hook))
(when display-flag
(pop-to-buffer buffer norecord))
buffer))