;;; simple.el --- basic editing commands for Emacs -*- lexical-binding: t -*-
-;; Copyright (C) 1985-1987, 1993-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1985-1987, 1993-2016 Free Software Foundation, Inc.
;; Maintainer: emacs-devel@gnu.org
;; Keywords: internal
(last-command-event ?\n)
;; Don't auto-fill if we have a numeric argument.
(auto-fill-function (if arg nil auto-fill-function))
+ (arg (prefix-numeric-value arg))
(postproc
;; Do the rest in post-self-insert-hook, because we want to do it
;; *before* other functions on that hook.
(lambda ()
- (cl-assert (eq ?\n (char-before)))
+ ;; We are not going to insert any newlines if arg is
+ ;; non-positive.
+ (or (and (numberp arg) (<= arg 0))
+ (cl-assert (eq ?\n (char-before))))
;; Mark the newline(s) `hard'.
(if use-hard-newlines
(set-hard-newline-properties
- (- (point) (prefix-numeric-value arg)) (point)))
+ (- (point) arg) (point)))
;; If the newline leaves the previous line blank, and we
;; have a left margin, delete that from the blank line.
(save-excursion
(move-to-left-margin nil t)))))
(unwind-protect
(if (not interactive)
- ;; FIXME: For non-interactive uses, many calls actually just want
- ;; (insert "\n"), so maybe we should do just that, so as to avoid
- ;; the risk of filling or running abbrevs unexpectedly.
- (let ((post-self-insert-hook (list postproc)))
- (self-insert-command (prefix-numeric-value arg)))
- (unwind-protect
- (progn
- (add-hook 'post-self-insert-hook postproc nil t)
- (self-insert-command (prefix-numeric-value arg)))
- ;; We first used let-binding to protect the hook, but that was naive
- ;; since add-hook affects the symbol-default value of the variable,
- ;; whereas the let-binding might only protect the buffer-local value.
- (remove-hook 'post-self-insert-hook postproc t)))
+ ;; FIXME: For non-interactive uses, many calls actually
+ ;; just want (insert "\n"), so maybe we should do just
+ ;; that, so as to avoid the risk of filling or running
+ ;; abbrevs unexpectedly.
+ (let ((post-self-insert-hook (list postproc)))
+ (self-insert-command arg))
+ (unwind-protect
+ (progn
+ (add-hook 'post-self-insert-hook postproc nil t)
+ (self-insert-command arg))
+ ;; We first used let-binding to protect the hook, but that
+ ;; was naive since add-hook affects the symbol-default
+ ;; value of the variable, whereas the let-binding might
+ ;; only protect the buffer-local value.
+ (remove-hook 'post-self-insert-hook postproc t)))
(cl-assert (not (member postproc post-self-insert-hook)))
(cl-assert (not (member postproc (default-value 'post-self-insert-hook))))))
nil)
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
- (while (forward-word 1)
+ (while (forward-word-strictly 1)
(setq words (1+ words)))))
words))
((use-region-p)
;; the end of the line when it fails to go to the next line.
(goto-char old-point)
(next-history-element arg)
+ ;; Reset `temporary-goal-column' because a correct value is not
+ ;; calculated when `next-line' above fails by bumping against
+ ;; the bottom of the minibuffer (bug#22544).
+ (setq temporary-goal-column 0)
;; Restore the original goal column on the last line
;; of possibly multi-line input.
(goto-char (point-max))
;; the beginning of the line when it fails to go to the previous line.
(goto-char old-point)
(previous-history-element arg)
+ ;; Reset `temporary-goal-column' because a correct value is not
+ ;; calculated when `previous-line' above fails by bumping against
+ ;; the top of the minibuffer (bug#22544).
+ (setq temporary-goal-column 0)
;; Restore the original goal column on the first line
;; of possibly multi-line input.
(goto-char (minibuffer-prompt-end))
(if (= (line-number-at-pos) 1)
(move-to-column (+ old-column (1- (minibuffer-prompt-end))))
(move-to-column old-column))
- (goto-char (line-end-position)))))))
+ ;; Put the cursor at the end of the visual line instead of the
+ ;; logical line, so the next `previous-line-or-history-element'
+ ;; would move to the previous history element, not to a possible upper
+ ;; visual line from the end of logical line in `line-move-visual' mode.
+ (end-of-visual-line)
+ ;; Since `end-of-visual-line' puts the cursor at the beginning
+ ;; of the next visual line, move it one char back to the end
+ ;; of the first visual line (bug#22544).
+ (unless (eolp) (backward-char 1)))))))
(defun next-complete-history-element (n)
"Get next history element which completes the minibuffer before the point.
have been made. By default `self-insert-command' and
`delete-char' are the only amalgamating commands, although this
function could be called by any command wishing to have this
-behaviour."
+behavior."
(let ((last-amalgamating-count
(undo-auto--last-boundary-amalgamating-number)))
(setq undo-auto--this-command-amalgamating t)
"Execute string COMMAND in inferior shell; display output, if any.
With prefix argument, insert the COMMAND's output at point.
+Interactively, prompt for COMMAND in the minibuffer.
+
If COMMAND ends in `&', execute it asynchronously.
The output appears in the buffer `*Async Shell Command*'.
That buffer is in shell mode. You can also use
(shell-command-on-region (point) (point) command
output-buffer nil error-buffer)))))))
-(defun display-message-or-buffer (message
- &optional buffer-name not-this-window frame)
+(defun display-message-or-buffer (message &optional buffer-name action frame)
"Display MESSAGE in the echo area if possible, otherwise in a pop-up buffer.
MESSAGE may be either a string or a buffer.
-A buffer is displayed using `display-buffer' if MESSAGE is too long for
-the maximum height of the echo area, as defined by `max-mini-window-height'
+A pop-up buffer is displayed using `display-buffer' if MESSAGE is too long
+for maximum height of the echo area, as defined by `max-mini-window-height'
if `resize-mini-windows' is non-nil.
Returns either the string shown in the echo area, or when a pop-up
string and it is displayed in the echo area, it is not specified whether
the contents are inserted into the buffer anyway.
-Optional arguments NOT-THIS-WINDOW and FRAME are as for `display-buffer',
-and only used if a buffer is displayed."
+Optional arguments ACTION and FRAME are as for `display-buffer',
+and are only used if a pop-up buffer is displayed."
(cond ((and (stringp message) (not (string-match "\n" message)))
;; Trivial case where we can use the echo area
(message "%s" message))
(t
;; Buffer
(goto-char (point-min))
- (display-buffer (current-buffer)
- not-this-window frame))))))))
+ (display-buffer (current-buffer) action frame))))))))
;; We have a sentinel to prevent insertion of a termination message
(setq prefix-command--last-echo nil)
(defun internal-echo-keystrokes-prefix ()
- ;; BEWARE: Called directly from the C code.
+ ;; BEWARE: Called directly from C code.
+ ;; If the return value is non-nil, it means we are in the middle of
+ ;; a command with prefix, such as a command invoked with prefix-arg.
(if (not prefix-command--needs-update)
prefix-command--last-echo
(setq prefix-command--last-echo
(defun backward-word (&optional arg)
"Move backward until encountering the beginning of a word.
With argument ARG, do this that many times.
-If ARG is omitted or nil, move point backward one word."
+If ARG is omitted or nil, move point backward one word.
+
+The word boundaries are normally determined by the buffer's syntax
+table, but `find-word-boundary-function-table', such as set up
+by `subword-mode', can change that. If a Lisp program needs to
+move by words determined strictly by the syntax table, it should
+use `backward-word-strictly' instead."
(interactive "^p")
(forward-word (- (or arg 1))))