📄 simple.el
字号:
(goto-char (region-beginning)) (goto-char (point-min))) (widen) (beginning-of-line) (setq start (point)) (goto-char opoint) (beginning-of-line) (let* ((buffer-line (1+ (count-lines 1 (point)))) (narrowed-p (or (/= start 1) (/= (point-max) (1+ (buffer-size))))) (narrowed-line (if narrowed-p (1+ (count-lines start (point))))) (selective-line (if selective-display (1+ (count-lines start (point) t)))) (region-line (if (region-active-p) (1+ (count-lines start (point) selective-display))))) (cond (region-line (message "Region line %d; Buffer line %d" region-line buffer-line)) ((and narrowed-p selective-line (/= selective-line narrowed-line)) ;; buffer narrowed and some lines selectively displayed (message "Collapsed line %d; Buffer line %d; Narrowed line %d" selective-line buffer-line narrowed-line)) (narrowed-p ;; buffer narrowed (message "Buffer line %d; Narrowed line %d" buffer-line narrowed-line)) ((and selective-line (/= selective-line buffer-line)) ;; some lines selectively displayed (message "Collapsed line %d; Buffer line %d" selective-line buffer-line)) (t ;; give a basic line count (message "Line %d" buffer-line))))))) (setq zmacs-region-stays t));;; Bob Weiner, Altrasoft, 02/12/1998;;; Added the 3rd arg in `count-lines' to conditionalize the counting of;;; collapsed lines.(defun count-lines (start end &optional ignore-invisible-lines-flag) "Return number of lines between START and END.This is usually the number of newlines between them,but can be one more if START is not equal to ENDand the greater of them is not at the start of a line.With optional IGNORE-INVISIBLE-LINES-FLAG non-nil, lines collapsed withselective-display are excluded from the line count." (save-excursion (save-restriction (narrow-to-region start end) (goto-char (point-min)) (if (and (not ignore-invisible-lines-flag) (eq selective-display t)) (save-match-data (let ((done 0)) (while (re-search-forward "[\n\C-m]" nil t 40) (setq done (+ 40 done))) (while (re-search-forward "[\n\C-m]" nil t 1) (setq done (+ 1 done))) (goto-char (point-max)) (if (and (/= start end) (not (bolp))) (1+ done) done))) (- (buffer-size) (forward-line (buffer-size)))))))(defun what-cursor-position () "Print info on cursor position (on screen and within buffer)." ;; XEmacs change (interactive "_") (let* ((char (char-after (point))) ; XEmacs (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 column-number-start-at-one 1 0)))) (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)) ;; XEmacs: don't use single-key-description (if (or (/= beg 1) (/= end (1+ total))) (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) <%d - %d> column %d %s" (text-char-description char) char char char pos total percent beg end col hscroll) (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) column %d %s" (text-char-description char) char 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));; XEmacs the following are declared elsewhere;(defvar read-expression-map (cons 'keymap minibuffer-local-map); "Minibuffer keymap used for reading Lisp expressions.");(define-key read-expression-map "\M-\t" 'lisp-complete-symbol);(put 'eval-expression 'disabled t);(defvar read-expression-history nil);; 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 &optional eval-expression-insert-value) "Evaluate EXPRESSION and print value in minibuffer.Value is also consed on to front of the variable `values'.With prefix argument, insert the result to the current buffer." ;(interactive "xEval: ") (interactive (list (read-from-minibuffer "Eval: " nil read-expression-map t 'read-expression-history) current-prefix-arg)) (setq values (cons (eval expression) values)) (prin1 (car values) (if eval-expression-insert-value (current-buffer) t)));; XEmacs -- extra parameter (variant, but equivalent logic)(defun edit-and-eval-command (prompt command &optional history) "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." (let ((command (read-expression prompt ;; first try to format the thing readably; ;; and if that fails, print it normally. (condition-case () (let ((print-readably t)) (prin1-to-string command)) (error (prin1-to-string command))) (or history '(command-history . 1))))) (or history (setq history 'command-history)) (if (consp history) (setq history (car history))) (if (eq history t) nil ;; If command was added to the history as a string, ;; get rid of that. We want only evallable expressions there. (if (stringp (car (symbol-value history))) (set history (cdr (symbol-value history)))) ;; If command to be redone does not match front of history, ;; add it to the history. (or (equal command (car (symbol-value history))) (set history (cons command (symbol-value history))))) (eval command)))(defun 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.You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]to get different commands to edit and resubmit." (interactive "p") ;; XEmacs: It looks like our version is better -sb (let ((print-level nil)) (edit-and-eval-command "Redo: " (or (nth (1- arg) command-history) (error "")) (cons 'command-history arg))));; XEmacs: Functions moved to minibuf.el;; previous-matching-history-element;; next-matching-history-element;; next-history-element;; previous-history-element;; next-complete-history-element;; previous-complete-history-element(defun goto-line (arg) "Goto line ARG, counting from line 1 at beginning of buffer." (interactive "NGoto line: ") (setq arg (prefix-numeric-value arg)) (save-restriction (widen) (goto-char 1) (if (eq selective-display t) (re-search-forward "[\n\C-m]" nil 'end (1- arg)) (forward-line (1- arg)))));Put this on C-x u, so we can force that rather than C-_ into startup msg(define-function '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") ;; If we don't get all the way through, make last-command indicate that ;; for the following command. (setq this-command t) (let ((modified (buffer-modified-p)) (recent-save (recent-auto-save-p))) (or (eq (selected-window) (minibuffer-window)) (display-message 'command "Undo!")) (or (and (eq last-command 'undo) (eq (current-buffer) last-undo-buffer)) ; XEmacs (progn (undo-start) (undo-more 1))) (undo-more (or arg 1)) ;; Don't specify a position in the undo record for the undo command. ;; Instead, undoing this should move point to where the change is. (let ((tail buffer-undo-list) done) (while (and tail (not done) (not (null (car tail)))) (if (integerp (car tail)) (progn (setq done t) (setq buffer-undo-list (delq (car tail) buffer-undo-list)))) (setq tail (cdr tail)))) (and modified (not (buffer-modified-p)) (delete-auto-save-file-if-necessary recent-save))) ;; If we do get all the way through, make this-command indicate that. (setq this-command 'undo))(defvar pending-undo-list nil "Within a run of consecutive undo commands, list remaining to be undone.")(defvar last-undo-buffer nil) ; XEmacs(defun undo-start () "Set `pending-undo-list' to the front of the undo list.The next call to `undo-more' will undo the most recently made change." (if (eq buffer-undo-list t) (error "No undo information in this buffer")) (setq pending-undo-list buffer-undo-list))(defun undo-more (count) "Undo back N undo-boundaries beyond what was already undone recently.Call `undo-start' to get ready to undo recent changes,then call `undo-more' one or more times to undo them." (or pending-undo-list (error "No further undo information")) (setq pending-undo-list (primitive-undo count pending-undo-list) last-undo-buffer (current-buffer))) ; XEmacs;; XEmacs(defun call-with-transparent-undo (fn &rest args) "Apply FN to ARGS, and then undo all changes made by FN to the currentbuffer. The undo records are processed even if FN returns non-locally.There is no trace of the changes made by FN in the buffer's undo history.You can use this in a write-file-hooks function with continue-save-bufferto make the contents of a disk file differ from its in-memory buffer." (let ((buffer-undo-list nil) ;; Kludge to prevent undo list truncation: (undo-high-threshold -1) (undo-threshold -1) (obuffer (current-buffer))) (unwind-protect (apply fn args) ;; Go to the buffer we will restore and make it writable: (set-buffer obuffer) (save-excursion (let ((buffer-read-only nil)) (save-restriction (widen) ;; Perform all undos, with further undo logging disabled: (let ((tail buffer-undo-list)) (setq buffer-undo-list t) (while tail (setq tail (primitive-undo (length tail) tail))))))))));; XEmacs: The following are in other files;; shell-command-history;; shell-command-switch;; shell-command;; shell-command-sentinel(defconst universal-argument-map (let ((map (make-sparse-keymap))) (set-keymap-default-binding map 'universal-argument-other-key) ;FSFmacs (define-key map [switch-frame] nil) (define-key map [(t)] 'universal-argument-other-key) (define-key map [(meta t)] 'universal-argument-other-key) (define-key map [(control u)] 'universal-argument-more) (define-key map [?-] 'universal-argument-minus) (define-key map [?0] 'digit-argument) (define-key map [?1] 'digit-argument) (define-key map [?2] 'digit-argument) (define-key map [?3] 'digit-argument) (define-key map [?4] 'digit-argument) (define-key map [?5] 'digit-argument) (define-key map [?6] 'digit-argument) (define-key map [?7] 'digit-argument) (define-key map [?8] 'digit-argument) (define-key map [?9] 'digit-argument) map) "Keymap used while processing \\[universal-argument].")(defvar universal-argument-num-events nil "Number of argument-specifying events read by `universal-argument'.`universal-argument-other-key' uses this to discard those eventsfrom (this-command-keys), and reread only the final command.")(defun universal-argument () "Begin a numeric argument for the following command.Digits or minus sign following \\[universal-argument] make up the numeric argument.\\[universal-argument] following the digits or minus sign ends the argument.\\[universal-argument] without digits or minus sign provides 4 as argument.Repeating \\[universal-argument] without digits or minus sign multiplies the argument by 4 each time." (interactive) (setq prefix-arg (list 4)) (setq zmacs-region-stays t) ; XEmacs (setq universal-argument-num-events (length (this-command-keys))) (setq overriding-terminal-local-map universal-argument-map));; A subsequent C-u means to multiply the factor by 4 if we've typed;; nothing but C-u's; otherwise it means to terminate the prefix arg.(defun universal-argument-more (arg) (interactive "_P") ; XEmacs (if (consp arg) (setq prefix-arg (list (* 4 (car arg)))) (setq prefix-arg arg) (setq overriding-terminal-local-map nil)) (setq universal-argument-num-events (length (this-command-keys))))(defun negative-argument (arg) "Begin a negative numeric argument for the next command.\\[universal-argument] following digits or minus sign ends the argument." (interactive "_P") ; XEmacs (cond ((integerp arg) (setq prefix-arg (- arg))) ((eq arg '-) (setq prefix-arg nil)) (t (setq prefix-arg '-))) (setq universal-argument-num-events (length (this-command-keys))) (setq overriding-terminal-local-map universal-argument-map));; XEmacs: This function not synched with FSF(defun digit-argument (arg) "Part of the numeric argument for the next command.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -