📄 simple.el
字号:
(and thisblank (not (looking-at "[ \t]*\n[ \t]*$")) (or (bobp) (progn (forward-line -1) (not (looking-at "[ \t]*$"))))))) ;; Delete preceding blank lines, and this one too if it's the only one. (if thisblank (progn (beginning-of-line) (if singleblank (forward-line 1)) (delete-region (point) (if (re-search-backward "[^ \t\n]" nil t) (progn (forward-line 1) (point)) (point-min))))) ;; Delete following blank lines, unless the current line is blank ;; and there are no following blank lines. (if (not (and thisblank singleblank)) (save-excursion (end-of-line) (forward-line 1) (delete-region (point) (if (re-search-forward "[^ \t\n]" nil t) (progn (beginning-of-line) (point)) (point-max))))) ;; Handle the special case where point is followed by newline and eob. ;; Delete the line, leaving point at eob. (if (looking-at "^[ \t]*\n\\'") (delete-region (point) (point-max)))))(defun back-to-indentation () "Move point to the first non-whitespace character on this line." ;; XEmacs change (interactive "_") (beginning-of-line 1) (skip-chars-forward " \t"))(defun newline-and-indent () "Insert a newline, then indent according to major mode.Indentation is done using the value of `indent-line-function'.In programming language modes, this is the same as TAB.In some text modes, where TAB inserts a tab, this command indents to thecolumn specified by the function `current-left-margin'." (interactive "*") (delete-region (point) (progn (skip-chars-backward " \t") (point))) (newline) (indent-according-to-mode))(defun reindent-then-newline-and-indent () "Reindent current line, insert newline, then indent the new line.Indentation of both lines is done according to the current major mode,which means calling the current value of `indent-line-function'.In programming language modes, this is the same as TAB.In some text modes, where TAB inserts a tab, this indents to thecolumn specified by the function `current-left-margin'." (interactive "*") (save-excursion (delete-region (point) (progn (skip-chars-backward " \t") (point))) (indent-according-to-mode)) (newline) (indent-according-to-mode));; Internal subroutine of delete-char(defun kill-forward-chars (arg) (if (listp arg) (setq arg (car arg))) (if (eq arg '-) (setq arg -1)) (kill-region (point) (+ (point) arg)));; Internal subroutine of backward-delete-char(defun kill-backward-chars (arg) (if (listp arg) (setq arg (car arg))) (if (eq arg '-) (setq arg -1)) (kill-region (point) (- (point) arg)))(defun backward-delete-char-untabify (arg &optional killp) "Delete characters backward, changing tabs into spaces.Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.Interactively, ARG is the prefix arg (default 1)and KILLP is t if a prefix arg was specified." (interactive "*p\nP") (let ((count arg)) (save-excursion (while (and (> count 0) (not (bobp))) (if (eq (char-before (point)) ?\t) ; XEmacs (let ((col (current-column))) (forward-char -1) (setq col (- col (current-column))) (insert-char ?\ col) (delete-char 1))) (forward-char -1) (setq count (1- count))))) (delete-backward-char arg killp) ;; XEmacs: In overwrite mode, back over columns while clearing them out, ;; unless at end of line. (and overwrite-mode (not (eolp)) (save-excursion (insert-char ?\ arg))))(defcustom delete-key-deletes-forward t "*If non-nil, the DEL key will erase one character forwards.If nil, the DEL key will erase one character backwards." :type 'boolean :group 'editing-basics)(defcustom backward-delete-function 'backward-delete-char "*Function called to delete backwards on a delete keypress.If `delete-key-deletes-forward' is nil, `backward-or-forward-delete-char'calls this function to erase one character backwards. Default valueis 'backward-delete-char, with 'backward-delete-char-untabify being apopular alternate setting." :type 'function :group 'editing-basics);; Trash me, baby.(defsubst delete-forward-p (); (and delete-key-deletes-forward; (or (not (eq (device-type) 'x)); (x-keysym-on-keyboard-sans-modifiers-p 'backspace)))) delete-key-deletes-forward)(defun backward-or-forward-delete-char (arg) "Delete either one character backwards or one character forwards.Controlled by the state of `delete-key-deletes-forward' and whether theBackSpace keysym even exists on your keyboard. If you don't have aBackSpace keysym, the delete key should always delete one characterbackwards." (interactive "*p") (if (delete-forward-p) (delete-char arg) (funcall backward-delete-function arg)))(defun backward-or-forward-kill-word (arg) "Delete either one word backwards or one word forwards.Controlled by the state of `delete-key-deletes-forward' and whether theBackSpace keysym even exists on your keyboard. If you don't have aBackSpace keysym, the delete key should always delete one characterbackwards." (interactive "*p") (if (delete-forward-p) (kill-word arg) (backward-kill-word arg)))(defun backward-or-forward-kill-sentence (arg) "Delete either one sentence backwards or one sentence forwards.Controlled by the state of `delete-key-deletes-forward' and whether theBackSpace keysym even exists on your keyboard. If you don't have aBackSpace keysym, the delete key should always delete one characterbackwards." (interactive "*P") (if (delete-forward-p) (kill-sentence arg) (backward-kill-sentence (prefix-numeric-value arg))))(defun backward-or-forward-kill-sexp (arg) "Delete either one sexpr backwards or one sexpr forwards.Controlled by the state of `delete-key-deletes-forward' and whether theBackSpace keysym even exists on your keyboard. If you don't have aBackSpace keysym, the delete key should always delete one characterbackwards." (interactive "*p") (if (delete-forward-p) (kill-sexp arg) (backward-kill-sexp arg)))(defun zap-to-char (arg char) "Kill up to and including ARG'th occurrence of CHAR.Goes backward if ARG is negative; error if CHAR not found." (interactive "*p\ncZap to char: ") (kill-region (point) (with-interactive-search-caps-disable-folding (char-to-string char) nil (search-forward (char-to-string char) nil nil arg) (point))))(defun zap-up-to-char (arg char) "Kill up to ARG'th occurrence of CHAR.Goes backward if ARG is negative; error if CHAR not found." (interactive "*p\ncZap up to char: ") (kill-region (point) (with-interactive-search-caps-disable-folding (char-to-string char) nil (search-forward (char-to-string char) nil nil arg) (goto-char (if (> arg 0) (1- (point)) (1+ (point)))) (point))))(defun beginning-of-buffer (&optional arg) "Move point to the beginning of the buffer; leave mark at previous position.With arg N, put point N/10 of the way from the beginning.If the buffer is narrowed, this command uses the beginning and sizeof the accessible part of the buffer.Don't use this command in Lisp programs!\(goto-char (point-min)) is faster and avoids clobbering the mark." ;; XEmacs change (interactive "_P") (push-mark) (let ((size (- (point-max) (point-min)))) (goto-char (if arg (+ (point-min) (if (> size 10000) ;; Avoid overflow for large buffer sizes! (* (prefix-numeric-value arg) (/ size 10)) (/ (+ 10 (* size (prefix-numeric-value arg))) 10))) (point-min)))) (if arg (forward-line 1)))(defun end-of-buffer (&optional arg) "Move point to the end of the buffer; leave mark at previous position.With arg N, put point N/10 of the way from the end.If the buffer is narrowed, this command uses the beginning and sizeof the accessible part of the buffer.Don't use this command in Lisp programs!\(goto-char (point-max)) is faster and avoids clobbering the mark." ;; XEmacs change (interactive "_P") (push-mark) ;; XEmacs changes here. (let ((scroll-to-end (not (pos-visible-in-window-p (point-max)))) (size (- (point-max) (point-min)))) (goto-char (if arg (- (point-max) (if (> size 10000) ;; Avoid overflow for large buffer sizes! (* (prefix-numeric-value arg) (/ size 10)) (/ (* size (prefix-numeric-value arg)) 10))) (point-max))) (cond (arg ;; If we went to a place in the middle of the buffer, ;; adjust it to the beginning of a line. (forward-line 1)) ;; XEmacs change (scroll-to-end ;; If the end of the buffer is not already on the screen, ;; then scroll specially to put it near, but not at, the bottom. (recenter -3)))));; XEmacs (not in FSF)(defun mark-beginning-of-buffer (&optional arg) "Push a mark at the beginning of the buffer; leave point where it is.With arg N, push mark N/10 of the way from the true beginning." (interactive "P") (push-mark (if arg (if (> (buffer-size) 10000) ;; Avoid overflow for large buffer sizes! (* (prefix-numeric-value arg) (/ (buffer-size) 10)) (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10)) (point-min)) nil t))(define-function 'mark-bob 'mark-beginning-of-buffer);; XEmacs (not in FSF)(defun mark-end-of-buffer (&optional arg) "Push a mark at the end of the buffer; leave point where it is.With arg N, push mark N/10 of the way from the true end." (interactive "P") (push-mark (if arg (- (1+ (buffer-size)) (if (> (buffer-size) 10000) ;; Avoid overflow for large buffer sizes! (* (prefix-numeric-value arg) (/ (buffer-size) 10)) (/ (* (buffer-size) (prefix-numeric-value arg)) 10))) (point-max)) nil t))(define-function 'mark-eob 'mark-end-of-buffer)(defun mark-whole-buffer () "Put point at beginning and mark at end of buffer.You probably should not use this function in Lisp programs;it is usually a mistake for a Lisp function to use any subroutinethat uses or sets the mark." (interactive) (push-mark (point)) (push-mark (point-max) nil t) (goto-char (point-min)));; XEmacs(defun eval-current-buffer (&optional printflag) "Evaluate the current buffer as Lisp code.Programs can pass argument PRINTFLAG which controls printing of output:nil means discard it; anything else is stream for print." (interactive) (eval-buffer (current-buffer) printflag));; XEmacs(defun count-words-buffer (&optional buffer) "Print the number of words in BUFFER.If called noninteractively, the value is returned rather than printed.BUFFER defaults to the current buffer." (interactive) (let ((words (count-words-region (point-min) (point-max) buffer))) (when (interactive-p) (message "Buffer has %d words" words)) words));; XEmacs(defun count-words-region (start end &optional buffer) "Print the number of words in region between START and END in BUFFER.If called noninteractively, the value is returned rather than printed.BUFFER defaults to the current buffer." (interactive "_r") (save-excursion (set-buffer (or buffer (current-buffer))) (let ((words 0)) (goto-char start) (while (< (point) end) (when (forward-word 1) (incf words))) (when (interactive-p) (message "Region has %d words" words)) words)))(defun count-lines-region (start end) "Print number of lines and characters in the region." ;; XEmacs change (interactive "_r") (message "Region has %d lines, %d characters" (count-lines start end) (- end start)));; XEmacs(defun count-lines-buffer (&optional buffer) "Print number of lines and characters in BUFFER." (interactive) (with-current-buffer (or buffer (current-buffer)) (let ((cnt (count-lines (point-min) (point-max)))) (message "Buffer has %d lines, %d characters" cnt (- (point-max) (point-min))) cnt)));;; Modified by Bob Weiner, 8/24/95, to print narrowed line number also.;;; Expanded by Bob Weiner, BeOpen, on 02/12/1997(defun what-line () "Print the following variants of the line number of point: Region line - displayed line within the active region Collapsed line - includes only selectively displayed lines; Buffer line - physical line in the buffer; Narrowed line - line number from the start of the buffer narrowing." ;; XEmacs change (interactive "_") (let ((opoint (point)) start) (save-excursion (save-restriction (if (region-active-p)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -