aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/simple.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/simple.el')
-rw-r--r--lisp/simple.el119
1 files changed, 68 insertions, 51 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index deb5c888c92..a22fe03a0ae 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -458,27 +458,18 @@ A non-nil INTERACTIVE argument means to run the `post-self-insert-hook'."
458 (put-text-property from (point) 'rear-nonsticky 458 (put-text-property from (point) 'rear-nonsticky
459 (cons 'hard sticky))))) 459 (cons 'hard sticky)))))
460 460
461(declare-function electric-indent-just-newline "electric") 461(defun open-line (n)
462(defun open-line (n &optional interactive)
463 "Insert a newline and leave point before it. 462 "Insert a newline and leave point before it.
464If `electric-indent-mode' is enabled, indent the new line if it's
465not empty.
466If there is a fill prefix and/or a `left-margin', insert them on 463If there is a fill prefix and/or a `left-margin', insert them on
467the new line. If the old line would have been blank, insert them 464the new line if the line would have been blank.
468on the old line as well. 465With arg N, insert N newlines."
469 466 (interactive "*p")
470With arg N, insert N newlines.
471A non-nil INTERACTIVE argument means to run the `post-self-insert-hook'."
472 (interactive "*p\np")
473 (let* ((do-fill-prefix (and fill-prefix (bolp))) 467 (let* ((do-fill-prefix (and fill-prefix (bolp)))
474 (do-left-margin (and (bolp) (> (current-left-margin) 0))) 468 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
475 (loc (point-marker)) 469 (loc (point-marker))
476 ;; Don't expand an abbrev before point. 470 ;; Don't expand an abbrev before point.
477 (abbrev-mode nil)) 471 (abbrev-mode nil))
478 (if (and interactive 472 (newline n)
479 (looking-at-p "[[:space:]]*$"))
480 (electric-indent-just-newline n)
481 (newline n interactive))
482 (goto-char loc) 473 (goto-char loc)
483 (while (> n 0) 474 (while (> n 0)
484 (cond ((bolp) 475 (cond ((bolp)
@@ -983,7 +974,8 @@ If DELETE is `delete-only', then only delete the region and the return value
983is undefined. If DELETE is nil, just return the content as a string. 974is undefined. If DELETE is nil, just return the content as a string.
984If DELETE is `bounds', then don't delete, but just return the 975If DELETE is `bounds', then don't delete, but just return the
985boundaries of the region as a list of (START . END) positions. 976boundaries of the region as a list of (START . END) positions.
986If anything else, delete the region and return its content as a string.") 977If anything else, delete the region and return its content as a string,
978after filtering it with `filter-buffer-substring'.")
987 979
988(defvar region-insert-function 980(defvar region-insert-function
989 (lambda (lines) 981 (lambda (lines)
@@ -1008,6 +1000,10 @@ Optional second arg KILLFLAG, if non-nil, means to kill (save in
1008kill ring) instead of delete. Interactively, N is the prefix 1000kill ring) instead of delete. Interactively, N is the prefix
1009arg, and KILLFLAG is set if N is explicitly specified. 1001arg, and KILLFLAG is set if N is explicitly specified.
1010 1002
1003When killing, the killed text is filtered by
1004`filter-buffer-substring' before it is saved in the kill ring, so
1005the actual saved text might be different from what was killed.
1006
1011In Overwrite mode, single character backward deletion may replace 1007In Overwrite mode, single character backward deletion may replace
1012tabs with spaces so as to back over columns, unless point is at 1008tabs with spaces so as to back over columns, unless point is at
1013the end of the line." 1009the end of the line."
@@ -1043,7 +1039,11 @@ To disable this, set variable `delete-active-region' to nil.
1043 1039
1044Optional second arg KILLFLAG non-nil means to kill (save in kill 1040Optional second arg KILLFLAG non-nil means to kill (save in kill
1045ring) instead of delete. Interactively, N is the prefix arg, and 1041ring) instead of delete. Interactively, N is the prefix arg, and
1046KILLFLAG is set if N was explicitly specified." 1042KILLFLAG is set if N was explicitly specified.
1043
1044When killing, the killed text is filtered by
1045`filter-buffer-substring' before it is saved in the kill ring, so
1046the actual saved text might be different from what was killed."
1047 (declare (interactive-only delete-char)) 1047 (declare (interactive-only delete-char))
1048 (interactive "p\nP") 1048 (interactive "p\nP")
1049 (unless (integerp n) 1049 (unless (integerp n)
@@ -2811,7 +2811,7 @@ an amalgamating command. The car of the list is the number of
2811times an amalgamating command has been called, and the cdr are the 2811times an amalgamating command has been called, and the cdr are the
2812buffers that were changed during the last command.") 2812buffers that were changed during the last command.")
2813 2813
2814(defvar undo-auto--current-boundary-timer nil 2814(defvar undo-auto-current-boundary-timer nil
2815 "Current timer which will run `undo-auto--boundary-timer' or nil. 2815 "Current timer which will run `undo-auto--boundary-timer' or nil.
2816 2816
2817If set to non-nil, this will effectively disable the timer.") 2817If set to non-nil, this will effectively disable the timer.")
@@ -2819,7 +2819,7 @@ If set to non-nil, this will effectively disable the timer.")
2819(defvar undo-auto--this-command-amalgamating nil 2819(defvar undo-auto--this-command-amalgamating nil
2820 "Non-nil if `this-command' should be amalgamated. 2820 "Non-nil if `this-command' should be amalgamated.
2821This variable is set to nil by `undo-auto--boundaries' and is set 2821This variable is set to nil by `undo-auto--boundaries' and is set
2822by `undo-auto--amalgamate'." ) 2822by `undo-auto-amalgamate'." )
2823 2823
2824(defun undo-auto--needs-boundary-p () 2824(defun undo-auto--needs-boundary-p ()
2825 "Return non-nil if `buffer-undo-list' needs a boundary at the start." 2825 "Return non-nil if `buffer-undo-list' needs a boundary at the start."
@@ -2829,7 +2829,7 @@ by `undo-auto--amalgamate'." )
2829 "Return the number of amalgamating last commands or nil. 2829 "Return the number of amalgamating last commands or nil.
2830Amalgamating commands are, by default, either 2830Amalgamating commands are, by default, either
2831`self-insert-command' and `delete-char', but can be any command 2831`self-insert-command' and `delete-char', but can be any command
2832that calls `undo-auto--amalgamate'." 2832that calls `undo-auto-amalgamate'."
2833 (car-safe undo-auto--last-boundary-cause)) 2833 (car-safe undo-auto--last-boundary-cause))
2834 2834
2835(defun undo-auto--ensure-boundary (cause) 2835(defun undo-auto--ensure-boundary (cause)
@@ -2860,13 +2860,13 @@ REASON describes the reason that the boundary is being added; see
2860 2860
2861(defun undo-auto--boundary-timer () 2861(defun undo-auto--boundary-timer ()
2862 "Timer which will run `undo--auto-boundary-timer'." 2862 "Timer which will run `undo--auto-boundary-timer'."
2863 (setq undo-auto--current-boundary-timer nil) 2863 (setq undo-auto-current-boundary-timer nil)
2864 (undo-auto--boundaries 'timer)) 2864 (undo-auto--boundaries 'timer))
2865 2865
2866(defun undo-auto--boundary-ensure-timer () 2866(defun undo-auto--boundary-ensure-timer ()
2867 "Ensure that the `undo-auto-boundary-timer' is set." 2867 "Ensure that the `undo-auto-boundary-timer' is set."
2868 (unless undo-auto--current-boundary-timer 2868 (unless undo-auto-current-boundary-timer
2869 (setq undo-auto--current-boundary-timer 2869 (setq undo-auto-current-boundary-timer
2870 (run-at-time 10 nil #'undo-auto--boundary-timer)))) 2870 (run-at-time 10 nil #'undo-auto--boundary-timer))))
2871 2871
2872(defvar undo-auto--undoably-changed-buffers nil 2872(defvar undo-auto--undoably-changed-buffers nil
@@ -2881,14 +2881,15 @@ See also `undo-auto--buffer-undoably-changed'.")
2881(defun undo-auto--add-boundary () 2881(defun undo-auto--add-boundary ()
2882 "Add an `undo-boundary' in appropriate buffers." 2882 "Add an `undo-boundary' in appropriate buffers."
2883 (undo-auto--boundaries 2883 (undo-auto--boundaries
2884 (if undo-auto--this-command-amalgamating 2884 (let ((amal undo-auto--this-command-amalgamating))
2885 'amalgamate 2885 (setq undo-auto--this-command-amalgamating nil)
2886 'command)) 2886 (if amal
2887 (setq undo-auto--this-command-amalgamating nil)) 2887 'amalgamate
2888 'command))))
2888 2889
2889(defun undo-auto--amalgamate () 2890(defun undo-auto-amalgamate ()
2890 "Amalgamate undo if necessary. 2891 "Amalgamate undo if necessary.
2891This function can be called after an amalgamating command. It 2892This function can be called before an amalgamating command. It
2892removes the previous `undo-boundary' if a series of such calls 2893removes the previous `undo-boundary' if a series of such calls
2893have been made. By default `self-insert-command' and 2894have been made. By default `self-insert-command' and
2894`delete-char' are the only amalgamating commands, although this 2895`delete-char' are the only amalgamating commands, although this
@@ -3359,13 +3360,12 @@ the use of a shell (with its need to quote arguments)."
3359 (shell-command-on-region (point) (point) command 3360 (shell-command-on-region (point) (point) command
3360 output-buffer nil error-buffer))))))) 3361 output-buffer nil error-buffer)))))))
3361 3362
3362(defun display-message-or-buffer (message 3363(defun display-message-or-buffer (message &optional buffer-name action frame)
3363 &optional buffer-name not-this-window frame)
3364 "Display MESSAGE in the echo area if possible, otherwise in a pop-up buffer. 3364 "Display MESSAGE in the echo area if possible, otherwise in a pop-up buffer.
3365MESSAGE may be either a string or a buffer. 3365MESSAGE may be either a string or a buffer.
3366 3366
3367A buffer is displayed using `display-buffer' if MESSAGE is too long for 3367A pop-up buffer is displayed using `display-buffer' if MESSAGE is too long
3368the maximum height of the echo area, as defined by `max-mini-window-height' 3368for maximum height of the echo area, as defined by `max-mini-window-height'
3369if `resize-mini-windows' is non-nil. 3369if `resize-mini-windows' is non-nil.
3370 3370
3371Returns either the string shown in the echo area, or when a pop-up 3371Returns either the string shown in the echo area, or when a pop-up
@@ -3377,8 +3377,8 @@ is used, defaulting to `*Message*'. In the case where MESSAGE is a
3377string and it is displayed in the echo area, it is not specified whether 3377string and it is displayed in the echo area, it is not specified whether
3378the contents are inserted into the buffer anyway. 3378the contents are inserted into the buffer anyway.
3379 3379
3380Optional arguments NOT-THIS-WINDOW and FRAME are as for `display-buffer', 3380Optional arguments ACTION and FRAME are as for `display-buffer',
3381and only used if a buffer is displayed." 3381and are only used if a pop-up buffer is displayed."
3382 (cond ((and (stringp message) (not (string-match "\n" message))) 3382 (cond ((and (stringp message) (not (string-match "\n" message)))
3383 ;; Trivial case where we can use the echo area 3383 ;; Trivial case where we can use the echo area
3384 (message "%s" message)) 3384 (message "%s" message))
@@ -3424,8 +3424,7 @@ and only used if a buffer is displayed."
3424 (t 3424 (t
3425 ;; Buffer 3425 ;; Buffer
3426 (goto-char (point-min)) 3426 (goto-char (point-min))
3427 (display-buffer (current-buffer) 3427 (display-buffer (current-buffer) action frame))))))))
3428 not-this-window frame))))))))
3429 3428
3430 3429
3431;; We have a sentinel to prevent insertion of a termination message 3430;; We have a sentinel to prevent insertion of a termination message
@@ -3817,7 +3816,9 @@ see other processes running on the system, use `list-system-processes'."
3817(setq prefix-command--last-echo nil) 3816(setq prefix-command--last-echo nil)
3818 3817
3819(defun internal-echo-keystrokes-prefix () 3818(defun internal-echo-keystrokes-prefix ()
3820 ;; BEWARE: Called directly from the C code. 3819 ;; BEWARE: Called directly from C code.
3820 ;; If the return value is non-nil, it means we are in the middle of
3821 ;; a command with prefix, such as a command invoked with prefix-arg.
3821 (if (not prefix-command--needs-update) 3822 (if (not prefix-command--needs-update)
3822 prefix-command--last-echo 3823 prefix-command--last-echo
3823 (setq prefix-command--last-echo 3824 (setq prefix-command--last-echo
@@ -4257,21 +4258,25 @@ The command \\[yank] can retrieve it from there.
4257If you want to append the killed region to the last killed text, 4258If you want to append the killed region to the last killed text,
4258use \\[append-next-kill] before \\[kill-region]. 4259use \\[append-next-kill] before \\[kill-region].
4259 4260
4261Any command that calls this function is a \"kill command\".
4262If the previous command was also a kill command,
4263the text killed this time appends to the text killed last time
4264to make one entry in the kill ring.
4265
4266The killed text is filtered by `filter-buffer-substring' before it is
4267saved in the kill ring, so the actual saved text might be different
4268from what was killed.
4269
4260If the buffer is read-only, Emacs will beep and refrain from deleting 4270If the buffer is read-only, Emacs will beep and refrain from deleting
4261the text, but put the text in the kill ring anyway. This means that 4271the text, but put the text in the kill ring anyway. This means that
4262you can use the killing commands to copy text from a read-only buffer. 4272you can use the killing commands to copy text from a read-only buffer.
4263 4273
4264Lisp programs should use this function for killing text. 4274Lisp programs should use this function for killing text.
4265 (To delete text, use `delete-region'.) 4275 (To delete text, use `delete-region'.)
4266Supply two arguments, character positions indicating the stretch of text 4276Supply two arguments, character positions BEG and END indicating the
4267 to be killed. 4277 stretch of text to be killed. If the optional argument REGION is
4268Any command that calls this function is a \"kill command\". 4278 non-nil, the function ignores BEG and END, and kills the current
4269If the previous command was also a kill command, 4279 region instead."
4270the text killed this time appends to the text killed last time
4271to make one entry in the kill ring.
4272
4273The optional argument REGION if non-nil, indicates that we're not just killing
4274some text between BEG and END, but we're killing the region."
4275 ;; Pass mark first, then point, because the order matters when 4280 ;; Pass mark first, then point, because the order matters when
4276 ;; calling `kill-append'. 4281 ;; calling `kill-append'.
4277 (interactive (list (mark) (point) 'region)) 4282 (interactive (list (mark) (point) 'region))
@@ -4316,8 +4321,14 @@ In Transient Mark mode, deactivate the mark.
4316If `interprogram-cut-function' is non-nil, also save the text for a window 4321If `interprogram-cut-function' is non-nil, also save the text for a window
4317system cut and paste. 4322system cut and paste.
4318 4323
4319The optional argument REGION if non-nil, indicates that we're not just copying 4324The copied text is filtered by `filter-buffer-substring' before it is
4320some text between BEG and END, but we're copying the region. 4325saved in the kill ring, so the actual saved text might be different
4326from what was in the buffer.
4327
4328When called from Lisp, save in the kill ring the stretch of text
4329between BEG and END, unless the optional argument REGION is
4330non-nil, in which case ignore BEG and END, and save the current
4331region instead.
4321 4332
4322This command's old key binding has been given to `kill-ring-save'." 4333This command's old key binding has been given to `kill-ring-save'."
4323 ;; Pass mark first, then point, because the order matters when 4334 ;; Pass mark first, then point, because the order matters when
@@ -4342,8 +4353,14 @@ system cut and paste.
4342If you want to append the killed line to the last killed text, 4353If you want to append the killed line to the last killed text,
4343use \\[append-next-kill] before \\[kill-ring-save]. 4354use \\[append-next-kill] before \\[kill-ring-save].
4344 4355
4345The optional argument REGION if non-nil, indicates that we're not just copying 4356The copied text is filtered by `filter-buffer-substring' before it is
4346some text between BEG and END, but we're copying the region. 4357saved in the kill ring, so the actual saved text might be different
4358from what was in the buffer.
4359
4360When called from Lisp, save in the kill ring the stretch of text
4361between BEG and END, unless the optional argument REGION is
4362non-nil, in which case ignore BEG and END, and save the current
4363region instead.
4347 4364
4348This command is similar to `copy-region-as-kill', except that it gives 4365This command is similar to `copy-region-as-kill', except that it gives
4349visual feedback indicating the extent of the region being copied." 4366visual feedback indicating the extent of the region being copied."
@@ -8269,7 +8286,7 @@ backward.
8269 8286
8270If set to nil, both Delete and Backspace keys delete backward. 8287If set to nil, both Delete and Backspace keys delete backward.
8271 8288
8272If set to 'maybe (which is the default), Emacs automatically 8289If set to `maybe' (which is the default), Emacs automatically
8273selects a behavior. On window systems, the behavior depends on 8290selects a behavior. On window systems, the behavior depends on
8274the keyboard used. If the keyboard has both a Backspace key and 8291the keyboard used. If the keyboard has both a Backspace key and
8275a Delete key, and both are mapped to their usual meanings, the 8292a Delete key, and both are mapped to their usual meanings, the