📄 simple.el
字号:
Most editing commands should not alter the mark.To remember a location for internal use in the Lisp program,store it in a Lisp variable. Example: (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." (set-marker (mark-marker) pos (current-buffer)))(defvar mark-ring nil "The list of saved former marks of the current buffer,most recent first.")(make-variable-buffer-local 'mark-ring)(defconst mark-ring-max 16 "*Maximum size of mark ring. Start discarding off end if gets this big.")(defun set-mark-command (arg) "Set mark at where point is, or jump to mark.With no prefix argument, set mark, and push previous mark on mark ring.With argument, jump to mark, and pop into mark off the mark ring.Novice emacs-lisp programmers often try to use the mark for the wrongpurposes. See the documentation of `set-mark' for more information." (interactive "P") (if (null arg) (push-mark) (if (null (mark)) (error "No mark set in this buffer") (goto-char (mark)) (pop-mark))))(defun push-mark (&optional location nomsg) "Set mark at LOCATION (point, by default) and push old mark on mark ring.Displays \"Mark set\" unless the optional second arg NOMSG is non-nil.Novice emacs-lisp programmers often try to use the mark for the wrongpurposes. See the documentation of `set-mark' for more information." (if (null (mark)) nil (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring)) (if (> (length mark-ring) mark-ring-max) (progn (move-marker (car (nthcdr mark-ring-max mark-ring)) nil) (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))) (set-mark (or location (point))) (or nomsg executing-macro (> (minibuffer-depth) 0) (message "Mark set")))(defun pop-mark () "Pop off mark ring into the buffer's actual mark.Does not set point. Does nothing if mark ring is empty." (if mark-ring (progn (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker))))) (set-mark (+ 0 (car mark-ring))) (move-marker (car mark-ring) nil) (if (null (mark)) (ding)) (setq mark-ring (cdr mark-ring)))))(fset 'exchange-dot-and-mark 'exchange-point-and-mark)(defun exchange-point-and-mark () "Put the mark where point is now, and point where the mark is now." (interactive nil) (let ((omark (mark))) (if (null omark) (error "No mark set in this buffer")) (set-mark (point)) (goto-char omark) nil))(defun next-line (arg) "Move cursor vertically down ARG lines.If there is no character in the target line exactly under the current column,the cursor is positioned after the character in that line which spans thiscolumn, or at the end of the line if it is not long enough.If there is no line in the buffer after this one,a newline character is inserted to create a lineand the cursor moves to that line.The command \\[set-goal-column] can be used to createa semipermanent goal column to which this command always moves.Then it does not try to move vertically.If you are thinking of using this in a Lisp program, considerusing `forward-line' instead. It is usually easier to useand more reliable (no dependence on goal column, etc.)." (interactive "p") (if (= arg 1) (let ((opoint (point))) (forward-line 1) (if (or (= opoint (point)) (not (eq (preceding-char) ?\n))) (insert ?\n) (goto-char opoint) (next-line-internal arg))) (next-line-internal arg)) nil)(defun previous-line (arg) "Move cursor vertically up ARG lines.If there is no character in the target line exactly over the current column,the cursor is positioned after the character in that line which spans thiscolumn, or at the end of the line if it is not long enough.The command \\[set-goal-column] can be used to createa semipermanent goal column to which this command always moves.Then it does not try to move vertically.If you are thinking of using this in a Lisp program, consider using`forward-line' with negative argument instead.. It is usually easierto use and more reliable (no dependence on goal column, etc.)." (interactive "p") (next-line-internal (- arg)) nil)(defconst track-eol nil "*Non-nil means vertical motion starting at the end of a line should keep to ends of lines.This means moving to the end of each line moved onto.")(defvar goal-column nil "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil.")(defvar temporary-goal-column 0 "Current goal column for vertical motion.It is the column where point was at the start of current run of vertical motion commands.")(defun next-line-internal (arg) (if (not (or (eq last-command 'next-line) (eq last-command 'previous-line))) (setq temporary-goal-column (if (and track-eol (eolp)) t (current-column)))) (if (not (integerp selective-display)) (forward-line arg) ;; Move by arg lines, but ignore invisible ones. (while (> arg 0) (vertical-motion 1) (forward-char -1) (forward-line 1) (setq arg (1- arg))) (while (< arg 0) (vertical-motion -1) (beginning-of-line) (setq arg (1+ arg)))) (if (eq (or goal-column temporary-goal-column) t) (end-of-line) (move-to-column (or goal-column temporary-goal-column))) nil)(defun set-goal-column (arg) "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].Those commands will move to this position in the line moved torather than trying to keep the same horizontal position.With a non-nil argument, clears out the goal columnso that \\[next-line] and \\[previous-line] resume vertical motion." (interactive "P") (if arg (progn (setq goal-column nil) (message "No goal column")) (setq goal-column (current-column)) (message (substitute-command-keys "Goal column %d (use \\[set-goal-column] with an arg to unset it)") goal-column)) nil)(defun transpose-chars (arg) "Interchange characters around point, moving forward one character.With prefix arg ARG, effect is to take character before pointand drag it forward past ARG other characters (backward if ARG negative).If no argument and at end of line, the previous two chars are exchanged." (interactive "*P") (and (null arg) (eolp) (forward-char -1)) (transpose-subr 'forward-char (prefix-numeric-value arg)))(defun transpose-words (arg) "Interchange words around point, leaving point at end of them.With prefix arg ARG, effect is to take word before or around pointand drag it forward past ARG other words (backward if ARG negative).If ARG is zero, the words around or after point and around or after markare interchanged." (interactive "*p") (transpose-subr 'forward-word arg))(defun transpose-sexps (arg) "Like \\[transpose-words] but applies to sexps.Does not work on a sexp that point is in the middle ofif it is a list or string." (interactive "*p") (transpose-subr 'forward-sexp arg))(defun transpose-lines (arg) "Exchange current line and previous line, leaving point after both.With argument ARG, takes previous line and moves it past ARG lines.With argument 0, interchanges line point is in with line mark is in." (interactive "*p") (transpose-subr (function (lambda (arg) (if (= arg 1) (progn ;; Move forward over a line, ;; but create a newline if none exists yet. (end-of-line) (if (eobp) (newline) (forward-char 1))) (forward-line arg)))) arg))(defun transpose-subr (mover arg) (let (start1 end1 start2 end2) (if (= arg 0) (progn (save-excursion (funcall mover 1) (setq end2 (point)) (funcall mover -1) (setq start2 (point)) (goto-char (mark)) (funcall mover 1) (setq end1 (point)) (funcall mover -1) (setq start1 (point)) (transpose-subr-1)) (exchange-point-and-mark))) (while (> arg 0) (funcall mover -1) (setq start1 (point)) (funcall mover 1) (setq end1 (point)) (funcall mover 1) (setq end2 (point)) (funcall mover -1) (setq start2 (point)) (transpose-subr-1) (goto-char end2) (setq arg (1- arg))) (while (< arg 0) (funcall mover -1) (setq start2 (point)) (funcall mover -1) (setq start1 (point)) (funcall mover 1) (setq end1 (point)) (funcall mover 1) (setq end2 (point)) (transpose-subr-1) (setq arg (1+ arg)))))(defun transpose-subr-1 () (if (> (min end1 end2) (max start1 start2)) (error "Don't have two things to transpose")) (let ((word1 (buffer-substring start1 end1)) (word2 (buffer-substring start2 end2))) (delete-region start2 end2) (goto-char start2) (insert word1) (goto-char (if (< start1 start2) start1 (+ start1 (- (length word1) (length word2))))) (delete-char (length word1)) (insert word2)))(defconst comment-column 32 "*Column to indent right-margin comments to.Setting this variable automatically makes it local to the current buffer.")(make-variable-buffer-local 'comment-column)(defconst comment-start nil "*String to insert to start a new comment, or nil if no comment syntax defined.")(defconst comment-start-skip nil "*Regexp to match the start of a comment plus everything up to its body.If there are any \\(...\\) pairs, the comment delimiter text is held to beginat the place matched by the close of the first pair.")(defconst comment-end "" "*String to insert to end a new comment.Should be an empty string if comments are terminated by end-of-line.")(defconst comment-indent-hook '(lambda () comment-column) "Function to compute desired indentation for a commentgiven the character number it starts at.")(defun indent-for-comment () "Indent this line's comment to comment column, or insert an empty comment." (interactive "*") (beginning-of-line 1) (if (null comment-start) (error "No comment syntax defined") (let* ((eolpos (save-excursion (end-of-line) (point))) cpos indent begpos) (if (re-search-forward comment-start-skip eolpos 'move) (progn (setq cpos (point-marker)) ;; Find the start of the comment delimiter. ;; If there were paren-pairs in comment-start-skip, ;; position at the end of the first pair. (if (match-end 1) (goto-char (match-end 1)) ;; If comment-start-skip matched a string with internal ;; whitespace (not final whitespace) then the delimiter ;; start at the end of that whitespace. ;; Otherwise, it starts at the beginning of what was matched. (skip-chars-backward " \t" (match-beginning 0)) (skip-chars-backward "^ \t" (match-beginning 0))))) (setq begpos (point)) ;; Compute desired indent. (if (= (current-column) (setq indent (funcall comment-indent-hook))) (goto-char begpos) ;; If that's different from current, change it. (skip-chars-backward " \t") (delete-region (point) begpos) (indent-to indent)) ;; An existing comment? (if cpos (progn (goto-char cpos) (set-marker cpos nil)) ;; No, insert one. (insert comment-start) (save-excursion (insert comment-end))))))(defun set-comment-column (arg) "Set the comment column based on point.With no arg, set the comment column to the current column.With just minus as arg, kill any comment on this line.With any other arg, set comment column to indentation of the previous comment and then align or create a comment on this line at that column." (interactive "P") (if (eq arg '-) (kill-comment nil) (if arg (progn (save-excursion (beginning-of-line) (re-search-backward comment-start-skip) (beginning-of-line) (re-search-forward comment-start-skip) (goto-char (match-beginning 0)) (setq comment-column (current-column)) (message "Comment column set to %d" comment-column)) (indent-for-comment)) (setq comment-column (current-column)) (message "Comment column set to %d" comment-column))))(defun kill-comment (arg) "Kill the comment on this line, if any.With argument, kill comments on that many lines starting with this one." (interactive "P")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -