📄 simple.el
字号:
(next-complex-command (- n)))(defun goto-line (arg) "Goto line ARG, counting from line 1 at beginning of buffer." (interactive "NGoto line: ") (save-restriction (widen) (goto-char 1) (forward-line (1- arg))));Put this on C-x u, so we can force that rather than C-_ into startup msg(fset 'advertised-undo 'undo)(defun undo (&optional arg) "Undo some previous changes.Repeat this command to undo more changes.A numeric argument serves as a repeat count." (interactive "*p") (let ((modified (buffer-modified-p))) (message "Undo!") (or (eq last-command 'undo) (progn (undo-start) (undo-more 1))) (setq this-command 'undo) (undo-more (or arg 1)) (and modified (not (buffer-modified-p)) (delete-auto-save-file-if-necessary))))(defun shell-command (command &optional flag) "Execute string COMMAND in inferior shell; display output, if any.Optional second arg non-nil (prefix arg, if interactive)means insert output in current buffer after point (leave mark after it)." (interactive "sShell command: \nP") (if flag (progn (barf-if-buffer-read-only) (push-mark) (call-process shell-file-name nil t nil "-c" command) (exchange-point-and-mark)) (shell-command-on-region (point) (point) command nil)))(defun shell-command-on-region (start end command &optional flag interactive) "Execute string COMMAND in inferior shell with region as input.Normally display output (if any) in temp buffer;Prefix arg means replace the region with it.Noninteractive args are START, END, COMMAND, FLAG.Noninteractively FLAG means insert output in place of text from START to END,and put point at the end, but don't alter the mark." (interactive "r\nsShell command on region: \nP\np") (if flag ;; Replace specified region with output from command. (let ((swap (and interactive (< (point) (mark))))) ;; Don't muck with mark ;; unless called interactively. (and interactive (push-mark)) (call-process-region start end shell-file-name t t nil "-c" command) (and interactive swap (exchange-point-and-mark))) (let ((buffer (get-buffer-create "*Shell Command Output*"))) (save-excursion (set-buffer buffer) (erase-buffer)) (if (eq buffer (current-buffer)) (setq start 1 end 1)) (call-process-region start end shell-file-name nil buffer nil "-c" command) (if (save-excursion (set-buffer buffer) (> (buffer-size) 0)) (set-window-start (display-buffer buffer) 1) (message "(Shell command completed with no output)")))))(defun universal-argument () "Begin a numeric argument for the following command.Digits or minus sign following this command make up the numeric argument.If no digits or minus sign follow, this command by itself provides 4 as argument.Used more than once, this command multiplies the argument by 4 each time." (interactive nil) (let ((c-u 4) (argstartchar last-command-char) char); (describe-arg (list c-u) 1) (setq char (read-char)) (while (= char argstartchar) (setq c-u (* 4 c-u)); (describe-arg (list c-u) 1) (setq char (read-char))) (prefix-arg-internal char c-u nil)))(defun prefix-arg-internal (char c-u value) (let ((sign 1)) (if (and (numberp value) (< value 0)) (setq sign -1 value (- value))) (if (eq value '-) (setq sign -1 value nil)); (describe-arg value sign) (while (= ?- char) (setq sign (- sign) c-u nil); (describe-arg value sign) (setq char (read-char))) (while (and (>= char ?0) (<= char ?9)) (setq value (+ (* (if (numberp value) value 0) 10) (- char ?0)) c-u nil); (describe-arg value sign) (setq char (read-char))) (setq prefix-arg (cond (c-u (list c-u)) ((numberp value) (* value sign)) ((= sign -1) '-))) (setq unread-command-char char)));(defun describe-arg (value sign); (cond ((numberp value); (message "Arg: %d" (* value sign))); ((consp value); (message "Arg: C-u factor %d" (car value))); ((< sign 0); (message "Arg: -"))))(defun digit-argument (arg) "Part of the numeric argument for the next command." (interactive "P") (prefix-arg-internal last-command-char nil arg))(defun negative-argument (arg) "Begin a negative numeric argument for the next command." (interactive "P") (prefix-arg-internal ?- nil arg))(defun forward-to-indentation (arg) "Move forward ARG lines and position at first nonblank character." (interactive "p") (forward-line arg) (skip-chars-forward " \t"))(defun backward-to-indentation (arg) "Move backward ARG lines and position at first nonblank character." (interactive "p") (forward-line (- arg)) (skip-chars-forward " \t"))(defun kill-line (&optional arg) "Kill the rest of the current line; if no nonblanks there, kill thru newline.With prefix argument, kill that many lines from point.Negative arguments kill lines backward.When calling from a program, nil means \"no arg\",a number counts as a prefix arg." (interactive "*P") (kill-region (point) (progn (if arg (forward-line (prefix-numeric-value arg)) (if (eobp) (signal 'end-of-buffer nil)) (if (looking-at "[ \t]*$") (forward-line 1) (end-of-line))) (point))));;;; The kill ring(defvar kill-ring nil "List of killed text sequences.")(defconst kill-ring-max 30 "*Maximum length of kill ring before oldest elements are thrown away.")(defvar kill-ring-yank-pointer nil "The tail of the kill ring whose car is the last thing yanked.")(defun kill-append (string before-p) (setcar kill-ring (if before-p (concat string (car kill-ring)) (concat (car kill-ring) string))))(defun kill-region (beg end) "Kill between point and mark.The text is deleted but saved in the kill ring.The command \\[yank] can retrieve it from there.\(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)This is the primitive for programs to kill text (as opposed to deleting it).Supply two arguments, character numbers indicating the stretch of text to be killed.Any command that calls this function is a \"kill command\".If the previous command was also a kill command,the text killed this time appends to the text killed last timeto make one entry in the kill ring." (interactive "*r") (if (and (not (eq buffer-undo-list t)) (not (eq last-command 'kill-region))) ;; Don't let the undo list be truncated before we can even access it. (let ((undo-high-threshold (+ (- (max beg end) (min beg end)) 100))) (delete-region beg end) ;; Take the same string recorded for undo ;; and put it in the kill-ring. (setq kill-ring (cons (car (car buffer-undo-list)) kill-ring)) (if (> (length kill-ring) kill-ring-max) (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)) (setq this-command 'kill-region) (setq kill-ring-yank-pointer kill-ring)) (copy-region-as-kill beg end) (delete-region beg end)))(fset 'kill-ring-save 'copy-region-as-kill)(defun copy-region-as-kill (beg end) "Save the region as if killed, but don't kill it." (interactive "r") (if (eq last-command 'kill-region) (kill-append (buffer-substring beg end) (< end beg)) (setq kill-ring (cons (buffer-substring beg end) kill-ring)) (if (> (length kill-ring) kill-ring-max) (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))) (setq this-command 'kill-region) (setq kill-ring-yank-pointer kill-ring))(defun append-next-kill () "Cause following command, if kill, to append to previous kill." (interactive) (if (interactive-p) (setq this-command 'kill-region) (setq last-command 'kill-region)))(defun rotate-yank-pointer (arg) "Rotate the yanking point in the kill ring." (interactive "p") (let ((length (length kill-ring))) (if (zerop length) (error "Kill ring is empty") (setq kill-ring-yank-pointer (nthcdr (% (+ arg (- length (length kill-ring-yank-pointer))) length) kill-ring)))))(defun yank-pop (arg) "Replace just-yanked stretch of killed-text with a different stretch.This command is allowed only immediately after a yank or a yank-pop.At such a time, the region contains a stretch of reinsertedpreviously-killed text. yank-pop deletes that text and inserts in itsplace a different stretch of killed text.With no argument, the previous kill is inserted.With argument n, the n'th previous kill is inserted.If n is negative, this is a more recent kill.The sequence of kills wraps around, so that after the oldest onecomes the newest one." (interactive "*p") (if (not (eq last-command 'yank)) (error "Previous command was not a yank")) (setq this-command 'yank) (let ((before (< (point) (mark)))) (delete-region (point) (mark)) (rotate-yank-pointer arg) (set-mark (point)) (insert (car kill-ring-yank-pointer)) (if before (exchange-point-and-mark))))(defun yank (&optional arg) "Reinsert the last stretch of killed text.More precisely, reinsert the stretch of killed text most recentlykilled OR yanked.With just C-U as argument, same but put point in front (and mark at end).With argument n, reinsert the nth most recently killed stretch of killedtext.See also the command \\[yank-pop]." (interactive "*P") (rotate-yank-pointer (if (listp arg) 0 (if (eq arg '-) -1 (1- arg)))) (push-mark (point)) (insert (car kill-ring-yank-pointer)) (if (consp arg) (exchange-point-and-mark)))(defun insert-buffer (buffer) "Insert after point the contents of BUFFER.Puts mark after the inserted text.BUFFER may be a buffer or a buffer name." (interactive "*bInsert buffer: ") (or (bufferp buffer) (setq buffer (get-buffer buffer))) (let (start end newmark) (save-excursion (save-excursion (set-buffer buffer) (setq start (point-min) end (point-max))) (insert-buffer-substring buffer start end) (setq newmark (point))) (push-mark newmark)))(defun append-to-buffer (buffer start end) "Append to specified buffer the text of the region.It is inserted into that buffer before its point.When calling from a program, give three arguments:a buffer or the name of one, and two character numbersspecifying the portion of the current buffer to be copied." (interactive "BAppend to buffer: \nr") (let ((oldbuf (current-buffer))) (save-excursion (set-buffer (get-buffer-create buffer)) (insert-buffer-substring oldbuf start end))))(defun prepend-to-buffer (buffer start end) "Prepend to specified buffer the text of the region.It is inserted into that buffer after its point.When calling from a program, give three arguments:a buffer or the name of one, and two character numbersspecifying the portion of the current buffer to be copied." (interactive "BPrepend to buffer: \nr") (let ((oldbuf (current-buffer))) (save-excursion (set-buffer (get-buffer-create buffer)) (save-excursion (insert-buffer-substring oldbuf start end)))))(defun copy-to-buffer (buffer start end) "Copy to specified buffer the text of the region.It is inserted into that buffer, replacing existing text there.When calling from a program, give three arguments:a buffer or the name of one, and two character numbersspecifying the portion of the current buffer to be copied." (interactive "BCopy to buffer: \nr") (let ((oldbuf (current-buffer))) (save-excursion (set-buffer (get-buffer-create buffer)) (erase-buffer) (save-excursion (insert-buffer-substring oldbuf start end)))))(defun mark () "Return this buffer's mark value as integer, or nil if no mark.If you are using this in an editing command, you are most likely makinga mistake; see the documentation of `set-mark'." (marker-position (mark-marker)))(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 wantthe user to see that the mark has moved, and you want the previousmark position to be lost.Normally, when a new mark is set, the old one should go on the stack.This is why most applications should use push-mark, not set-mark.Novice emacs-lisp programmers often try to use the mark for the wrongpurposes. The mark saves a location for the user's convenience.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -