📄 simple.el
字号:
(barf-if-buffer-read-only) (let ((count (prefix-numeric-value arg))) (beginning-of-line) (while (> count 0) (let ((eolpos (save-excursion (end-of-line) (point)))) (if (re-search-forward comment-start-skip eolpos t) (progn (goto-char (match-beginning 0)) (skip-chars-backward " \t") (kill-region (point) eolpos)))) (if arg (forward-line 1)) (setq count (1- count)))))(defun backward-word (arg) "Move backward until encountering the end of a word.With argument, do this that many times.In programs, it is faster to call forward-word with negative arg." (interactive "p") (forward-word (- arg)))(defun mark-word (arg) "Set mark arg words away from point." (interactive "p") (push-mark (save-excursion (forward-word arg) (point))))(defun kill-word (arg) "Kill characters forward until encountering the end of a word.With argument, do this that many times." (interactive "*p") (kill-region (point) (progn (forward-word arg) (point))))(defun backward-kill-word (arg) "Kill characters backward until encountering the end of a word.With argument, do this that many times." (interactive "*p") (kill-word (- arg)))(defconst fill-prefix nil "*String for filling to insert at front of new line, or nil for none.Setting this variable automatically makes it local to the current buffer.")(make-variable-buffer-local 'fill-prefix)(defun do-auto-fill () (let ((fill-point (let ((opoint (point))) (save-excursion (move-to-column (1+ fill-column)) (skip-chars-backward "^ \t\n") (if (bolp) (re-search-forward "[ \t]" opoint t)) (skip-chars-backward " \t") (point))))) ;; If there is a space on the line before fill-point, ;; and nonspaces precede it, break the line there. (if (save-excursion (goto-char fill-point) (not (bolp))) ;; If point is at the fill-point, do not `save-excursion'. ;; Otherwise, if a comment prefix or fill-prefix is inserted, ;; point will end up before it rather than after it. (if (save-excursion (skip-chars-backward " \t") (= (point) fill-point)) (indent-new-comment-line) (save-excursion (goto-char fill-point) (indent-new-comment-line))))))(defconst comment-multi-line nil "*Non-nil means \\[indent-new-comment-line] should continue same commenton new line, with no new terminator or starter.")(defun indent-new-comment-line () "Break line at point and indent, continuing comment if presently within one.The body of the continued comment is indented under the previous comment line." (interactive "*") (let (comcol comstart) (skip-chars-backward " \t") (delete-region (point) (progn (skip-chars-forward " \t") (point))) (insert ?\n) (save-excursion (if (and comment-start-skip (let ((opoint (point))) (forward-line -1) (re-search-forward comment-start-skip opoint t))) ;; The old line is a comment. ;; Set WIN to the pos of the comment-start. ;; But if the comment is empty, look at preceding lines ;; to find one that has a nonempty comment. (let ((win (match-beginning 0))) (while (and (eolp) (not (bobp)) (let (opoint) (beginning-of-line) (setq opoint (point)) (forward-line -1) (re-search-forward comment-start-skip opoint t))) (setq win (match-beginning 0))) ;; Indent this line like what we found. (goto-char win) (setq comcol (current-column)) (setq comstart (buffer-substring (point) (match-end 0)))))) (if comcol (let ((comment-column comcol) (comment-start comstart) (comment-end comment-end)) (and comment-end (not (equal comment-end "")) (if (not comment-multi-line) (progn (forward-char -1) (insert comment-end) (forward-char 1)) (setq comment-column (+ comment-column (length comment-start)) comment-start ""))) (if (not (eolp)) (setq comment-end "")) (insert ?\n) (forward-char -1) (indent-for-comment) (delete-char 1)) (if fill-prefix (insert fill-prefix) (indent-according-to-mode)))))(defun auto-fill-mode (arg) "Toggle auto-fill mode.With arg, turn auto-fill mode on iff arg is positive.In auto-fill mode, inserting a space at a column beyond fill-columnautomatically breaks the line at a previous space." (interactive "P") (prog1 (setq auto-fill-hook (if (if (null arg) (not auto-fill-hook) (> (prefix-numeric-value arg) 0)) 'do-auto-fill nil)) ;; update mode-line (set-buffer-modified-p (buffer-modified-p))))(defun turn-on-auto-fill () "Unconditionally turn on Auto Fill mode." (auto-fill-mode 1))(defun set-fill-column (arg) "Set fill-column to current column, or to argument if given.fill-column's value is separate for each buffer." (interactive "P") (setq fill-column (if (integerp arg) arg (current-column))) (message "fill-column set to %d" fill-column))(defun set-selective-display (arg) "Set selective-display to ARG; clear it if no arg.When selective-display is a number > 0,lines whose indentation is >= selective-display are not displayed.selective-display's value is separate for each buffer." (interactive "P") (if (eq selective-display t) (error "selective-display already in use for marked lines")) (setq selective-display (and arg (prefix-numeric-value arg))) (set-window-start (selected-window) (window-start (selected-window))) (princ "selective-display set to " t) (prin1 selective-display t) (princ "." t))(defun overwrite-mode (arg) "Toggle overwrite mode.With arg, turn overwrite mode on iff arg is positive.In overwrite mode, printing characters typed in replace existing texton a one-for-one basis, rather than pushing it to the right." (interactive "P") (setq overwrite-mode (if (null arg) (not overwrite-mode) (> (prefix-numeric-value arg) 0))) (set-buffer-modified-p (buffer-modified-p))) ;No-op, but updates mode line.(defconst blink-matching-paren t "*Non-nil means show matching open-paren when close-paren is inserted.")(defconst blink-matching-paren-distance 4000 "*If non-nil, is maximum distance to search for matching open-parenwhen close-paren is inserted.")(defun blink-matching-open () "Move cursor momentarily to the beginning of the sexp before point." (and (> (point) (1+ (point-min))) (/= (char-syntax (char-after (- (point) 2))) ?\\ ) blink-matching-paren (let* ((oldpos (point)) (blinkpos) (mismatch)) (save-excursion (save-restriction (if blink-matching-paren-distance (narrow-to-region (max (point-min) (- (point) blink-matching-paren-distance)) oldpos)) (condition-case () (setq blinkpos (scan-sexps oldpos -1)) (error nil))) (and blinkpos (/= (char-syntax (char-after blinkpos)) ?\$) (setq mismatch (/= (char-after (1- oldpos)) (logand (lsh (aref (syntax-table) (char-after blinkpos)) -8) 255)))) (if mismatch (setq blinkpos nil)) (if blinkpos (progn (goto-char blinkpos) (if (pos-visible-in-window-p) (sit-for 1) (goto-char blinkpos) (message "Matches %s" (if (save-excursion (skip-chars-backward " \t") (not (bolp))) (buffer-substring (progn (beginning-of-line) (point)) (1+ blinkpos)) (buffer-substring blinkpos (progn (forward-char 1) (skip-chars-forward "\n \t") (end-of-line) (point))))))) (cond (mismatch (message "Mismatched parentheses")) ((not blink-matching-paren-distance) (message "Unmatched parenthesis"))))))));Turned off because it makes dbx bomb out.(setq blink-paren-hook 'blink-matching-open); this is just something for the luser to see in a keymap -- this is not; how quitting works normally!(defun keyboard-quit () "Signal a quit condition." (interactive) (signal 'quit nil))(define-key global-map "\C-g" 'keyboard-quit)(defun set-variable (var val) "Set VARIABLE to VALUE. VALUE is a Lisp object.When using this interactively, supply a Lisp expression for VALUE.If you want VALUE to be a string, you must surround it with doublequotes." (interactive (let* ((var (read-variable "Set variable: ")) (minibuffer-help-form '(funcall myhelp)) (myhelp (function (lambda () (with-output-to-temp-buffer "*Help*" (prin1 var) (princ "\nDocumentation:\n") (princ (substring (documentation-property var 'variable-documentation) 1)) (if (boundp var) (let ((print-length 20)) (princ "\n\nCurrent value: ") (prin1 (symbol-value var)))) nil))))) (list var (eval-minibuffer (format "Set %s to value: " var))))) (set var val));These commands are defined in editfns.c;but they are not assigned to keys there.(put 'narrow-to-region 'disabled t)(define-key ctl-x-map "n" 'narrow-to-region)(define-key ctl-x-map "w" 'widen)(define-key global-map "\C-j" 'newline-and-indent)(define-key global-map "\C-m" 'newline)(define-key global-map "\C-o" 'open-line)(define-key esc-map "\C-o" 'split-line)(define-key global-map "\C-q" 'quoted-insert)(define-key esc-map "^" 'delete-indentation)(define-key esc-map "\\" 'delete-horizontal-space)(define-key esc-map "m" 'back-to-indentation)(define-key ctl-x-map "\C-o" 'delete-blank-lines)(define-key esc-map " " 'just-one-space)(define-key esc-map "z" 'zap-to-char)(define-key esc-map "=" 'count-lines-region)(define-key ctl-x-map "=" 'what-cursor-position)(define-key esc-map "\e" 'eval-expression)(define-key ctl-x-map "\e" 'repeat-complex-command)(define-key ctl-x-map "u" 'advertised-undo)(define-key global-map "\C-_" 'undo)(define-key esc-map "!" 'shell-command)(define-key esc-map "|" 'shell-command-on-region)(define-key global-map "\C-u" 'universal-argument)(let ((i ?0)) (while (<= i ?9) (define-key esc-map (char-to-string i) 'digit-argument) (setq i (1+ i))))(define-key esc-map "-" 'negative-argument)(define-key global-map "\C-k" 'kill-line)(define-key global-map "\C-w" 'kill-region)(define-key esc-map "w" 'copy-region-as-kill)(define-key esc-map "\C-w" 'append-next-kill)(define-key global-map "\C-y" 'yank)(define-key esc-map "y" 'yank-pop)(define-key ctl-x-map "a" 'append-to-buffer)(define-key global-map "\C-@" 'set-mark-command)(define-key ctl-x-map "\C-x" 'exchange-point-and-mark)(define-key global-map "\C-n" 'next-line)(define-key global-map "\C-p" 'previous-line)(define-key ctl-x-map "\C-n" 'set-goal-column)(define-key global-map "\C-t" 'transpose-chars)(define-key esc-map "t" 'transpose-words)(define-key esc-map "\C-t" 'transpose-sexps)(define-key ctl-x-map "\C-t" 'transpose-lines)(define-key esc-map ";" 'indent-for-comment)(define-key esc-map "j" 'indent-new-comment-line)(define-key esc-map "\C-j" 'indent-new-comment-line)(define-key ctl-x-map ";" 'set-comment-column)(define-key ctl-x-map "f" 'set-fill-column)(define-key ctl-x-map "$" 'set-selective-display)(define-key esc-map "@" 'mark-word)(define-key esc-map "f" 'forward-word)(define-key esc-map "b" 'backward-word)(define-key esc-map "d" 'kill-word)(define-key esc-map "\177" 'backward-kill-word)(define-key esc-map "<" 'beginning-of-buffer)(define-key esc-map ">" 'end-of-buffer)(define-key ctl-x-map "h" 'mark-whole-buffer)(define-key esc-map "\\" 'delete-horizontal-space)(fset 'mode-specific-command-prefix (make-sparse-keymap))(defconst mode-specific-map (symbol-function 'mode-specific-command-prefix) "Keymap for characters following C-c.")(define-key global-map "\C-c" 'mode-specific-command-prefix)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -