📄 simple.el
字号:
;; Basic editing commands for Emacs;; Copyright (C) 1985, 1986, 1987 Free Software Foundation, Inc.;; This file is part of GNU Emacs.;; GNU Emacs is free software; you can redistribute it and/or modify;; it under the terms of the GNU General Public License as published by;; the Free Software Foundation; either version 1, or (at your option);; any later version.;; GNU Emacs is distributed in the hope that it will be useful,;; but WITHOUT ANY WARRANTY; without even the implied warranty of;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the;; GNU General Public License for more details.;; You should have received a copy of the GNU General Public License;; along with GNU Emacs; see the file COPYING. If not, write to;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.(defun open-line (arg) "Insert a newline and leave point before it.With arg, inserts that many newlines." (interactive "*p") (let ((flag (and (bolp) (not (bobp))))) (if flag (forward-char -1)) (while (> arg 0) (insert ?\n) (goto-char (1- (point))) (setq arg (1- arg))) (if flag (forward-char 1))))(defun split-line () "Split current line, moving portion beyond point vertically down." (interactive "*") (skip-chars-forward " \t") (let ((col (current-column)) (pos (point))) (insert ?\n) (indent-to col 0) (goto-char pos)))(defun quoted-insert (arg) "Read next input character and insert it.Useful for inserting control characters.You may also type up to 3 octal digits, to insert a character with that code" (interactive "*p") (let ((char (read-quoted-char))) (while (> arg 0) (insert char) (setq arg (1- arg)))))(defun delete-indentation (&optional arg) "Join this line to previous and fix up whitespace at join.With argument, join this line to following line." (interactive "*P") (beginning-of-line) (if arg (forward-line 1)) (if (eq (preceding-char) ?\n) (progn (delete-region (point) (1- (point))) (fixup-whitespace))))(defun fixup-whitespace () "Fixup white space between objects around point.Leave one space or none, according to the context." (interactive "*") (save-excursion (delete-horizontal-space) (if (or (looking-at "^\\|\\s)") (save-excursion (forward-char -1) (looking-at "$\\|\\s(\\|\\s'"))) nil (insert ?\ ))))(defun delete-horizontal-space () "Delete all spaces and tabs around point." (interactive "*") (skip-chars-backward " \t") (delete-region (point) (progn (skip-chars-forward " \t") (point))))(defun just-one-space () "Delete all spaces and tabs around point, leaving one space." (interactive "*") (skip-chars-backward " \t") (if (= (following-char) ? ) (forward-char 1) (insert ? )) (delete-region (point) (progn (skip-chars-forward " \t") (point))))(defun delete-blank-lines () "On blank line, delete all surrounding blank lines, leaving just one.On isolated blank line, delete that one.On nonblank line, delete all blank lines that follow it." (interactive "*") (let (thisblank singleblank) (save-excursion (beginning-of-line) (setq thisblank (looking-at "[ \t]*$")) (setq singleblank (and thisblank (not (looking-at "[ \t]*\n[ \t]*$")) (or (bobp) (progn (forward-line -1) (not (looking-at "[ \t]*$"))))))) (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))))) (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)))))))(defun back-to-indentation () "Move point to the first non-whitespace character on this line." (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 current 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 thespecified left-margin column." (interactive "*") (delete-region (point) (progn (skip-chars-backward " \t") (point))) (insert ?\n) (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 that the current value of indent-line-function is called.In programming language modes, this is the same as TAB.In some text modes, where TAB inserts a tab, this indents to thespecified left-margin column." (interactive "*") (save-excursion (delete-region (point) (progn (skip-chars-backward " \t") (point))) (indent-according-to-mode)) (insert ?\n) (indent-according-to-mode))(defun kill-forward-chars (arg) (if (listp arg) (setq arg (car arg))) (if (eq arg '-) (setq arg -1)) (kill-region (point) (+ (point) arg)))(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 prefix arg is was specified." (interactive "*p\nP") (let ((count arg)) (save-excursion (while (and (> count 0) (not (bobp))) (if (= (preceding-char) ?\t) (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))(defun zap-to-char (arg char) "Kill up to (but not including) ARG'th occurrence of CHAR.Goes backward if ARG is negative; goes to end of buffer if CHAR not found." (interactive "*p\ncZap to char: ") (kill-region (point) (if (search-forward (char-to-string char) nil t arg) (progn (goto-char (if (> arg 0) (1- (point)) (1+ (point)))) (point)) (if (> arg 0) (point-max) (point-min)))))(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 true beginning.Don't use this in Lisp programs!\(goto-char (point-min)) is faster and does not set the mark." (interactive "P") (push-mark) (goto-char (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))) (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 true end.Don't use this in Lisp programs!\(goto-char (point-max)) is faster and does not set the mark." (interactive "P") (push-mark) (goto-char (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))) (if arg (forward-line 1)))(defun mark-whole-buffer () "Put point at beginning and mark at end of buffer." (interactive) (push-mark (point)) (push-mark (point-max)) (goto-char (point-min)))(defun count-lines-region (start end) "Print number of lines in the region." (interactive "r") (message "Region has %d lines" (count-lines start end)))(defun what-line () "Print the current line number (in the buffer) of point." (interactive) (save-restriction (widen) (save-excursion (beginning-of-line) (message "Line %d" (1+ (count-lines 1 (point)))))))(defun count-lines (start end) "Return number of newlines between START and END." (save-excursion (save-restriction (narrow-to-region start end) (goto-char (point-min)) (- (buffer-size) (forward-line (buffer-size))))))(defun what-cursor-position () "Print info on cursor position (on screen and within buffer)." (interactive) (let* ((char (following-char)) (beg (point-min)) (end (point-max)) (pos (point)) (total (buffer-size)) (percent (if (> total 50000) ;; Avoid overflow from multiplying by 100! (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1)) (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1)))) (hscroll (if (= (window-hscroll) 0) "" (format " Hscroll=%d" (window-hscroll)))) (col (current-column))) (if (= pos end) (if (or (/= beg 1) (/= end (1+ total))) (message "point=%d of %d(%d%%) <%d - %d> column %d %s" pos total percent beg end col hscroll) (message "point=%d of %d(%d%%) column %d %s" pos total percent col hscroll)) (if (or (/= beg 1) (/= end (1+ total))) (message "Char: %s (0%o) point=%d of %d(%d%%) <%d - %d> column %d %s" (single-key-description char) char pos total percent beg end col hscroll) (message "Char: %s (0%o) point=%d of %d(%d%%) column %d %s" (single-key-description char) char pos total percent col hscroll)))))(defun fundamental-mode () "Major mode not specialized for anything in particular.Other major modes are defined by comparison with this one." (interactive) (kill-all-local-variables))(put 'eval-expression 'disabled t);; We define this, rather than making eval interactive,;; for the sake of completion of names like eval-region, eval-current-buffer.(defun eval-expression (expression) "Evaluate EXPRESSION and print value in minibuffer.Value is also consed on to front of variable values 's value." (interactive "xEval: ") (setq values (cons (eval expression) values)) (prin1 (car values) t))(defun edit-and-eval-command (prompt command) "Prompting with PROMPT, let user edit COMMAND and eval result.COMMAND is a Lisp expression. Let user edit that expression inthe minibuffer, then read and evaluate the result." (eval (read-minibuffer prompt (prin1-to-string command))))(defvar repeat-complex-command-map (copy-alist minibuffer-local-map))(define-key repeat-complex-command-map "\ep" 'previous-complex-command)(define-key repeat-complex-command-map "\en" 'next-complex-command)(defun repeat-complex-command (repeat-complex-command-arg) "Edit and re-evaluate last complex command, or ARGth from last.A complex command is one which used the minibuffer.The command is placed in the minibuffer as a Lisp form for editing.The result is executed, repeating the command as changed.If the command has been changed or is not the most recent previous commandit is added to the front of the command history.Whilst editing the command, the following commands are available:\\{repeat-complex-command-map}" (interactive "p") (let ((elt (nth (1- repeat-complex-command-arg) command-history)) newcmd) (if elt (progn (setq newcmd (read-from-minibuffer "Redo: " (prin1-to-string elt) repeat-complex-command-map t)) ;; If command to be redone does not match front of history, ;; add it to the history. (or (equal newcmd (car command-history)) (setq command-history (cons newcmd command-history))) (eval newcmd)) (ding))))(defun next-complex-command (n) "Inserts the next element of `command-history' into the minibuffer." (interactive "p") (let ((narg (min (max 1 (- repeat-complex-command-arg n)) (length command-history)))) (if (= repeat-complex-command-arg narg) (error (if (= repeat-complex-command-arg 1) "No following item in command history" "No preceeding item command history")) (erase-buffer) (setq repeat-complex-command-arg narg) (insert (prin1-to-string (nth (1- repeat-complex-command-arg) command-history))) (goto-char (point-min)))))(defun previous-complex-command (n) "Inserts the previous element of `command-history' into the minibuffer." (interactive "p")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -