;;; simple.el --- basic editing commands for Emacs
;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-;; 2000, 2001, 2002, 2003, 2004, 2005
-;; Free Software Foundation, Inc.
+;; 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
;; Maintainer: FSF
;; Keywords: internal
(autoload 'widget-convert "wid-edit")
(autoload 'shell-mode "shell"))
+(defvar compilation-current-error)
+
(defcustom idle-update-delay 0.5
"*Idle time delay before updating various things on the screen.
Various Emacs features that update auxiliary information when point moves
(funcall next-error-function (prefix-numeric-value arg) reset)
(run-hooks 'next-error-hook))))
+(defun next-error-internal ()
+ "Visit the source code corresponding to the `next-error' message at point."
+ (setq next-error-last-buffer (current-buffer))
+ ;; we know here that next-error-function is a valid symbol we can funcall
+ (with-current-buffer next-error-last-buffer
+ (funcall next-error-function 0 nil)
+ (run-hooks 'next-error-hook)))
+
(defalias 'goto-next-locus 'next-error)
(defalias 'next-match 'next-error)
When turned on, cursor motion in the compilation, grep, occur or diff
buffer causes automatic display of the corresponding source code
location."
- :group 'next-error :init-value " Fol"
+ :group 'next-error :init-value nil :lighter " Fol"
(if (not next-error-follow-minor-mode)
(remove-hook 'post-command-hook 'next-error-follow-mode-post-command-hook t)
(add-hook 'post-command-hook 'next-error-follow-mode-post-command-hook nil t)
- (make-variable-buffer-local 'next-error-follow-last-line)))
+ (make-local-variable 'next-error-follow-last-line)))
;;; Used as a `post-command-hook' by `next-error-follow-mode'
;;; for the *Compilation* *grep* and *Occur* buffers.
(message "point=%d of %d (%d%%) column %d %s"
pos total percent col hscroll))
(let ((coding buffer-file-coding-system)
- encoded encoding-msg)
+ encoded encoding-msg display-prop under-display)
(if (or (not coding)
(eq (coding-system-type coding) t))
(setq coding default-buffer-file-coding-system))
(if (eq (char-charset char) 'eight-bit)
(setq encoding-msg
(format "(0%o, %d, 0x%x, raw-byte)" char char char))
- (setq encoded (and (>= char 128) (encode-coding-char char coding)))
+ ;; Check if the character is displayed with some `display'
+ ;; text property. In that case, set under-display to the
+ ;; buffer substring covered by that property.
+ (setq display-prop (get-text-property pos 'display))
+ (if display-prop
+ (let ((to (or (next-single-property-change pos 'display)
+ (point-max))))
+ (if (< to (+ pos 4))
+ (setq under-display "")
+ (setq under-display "..."
+ to (+ pos 4)))
+ (setq under-display
+ (concat (buffer-substring-no-properties pos to)
+ under-display)))
+ (setq encoded (and (>= char 128) (encode-coding-char char coding))))
(setq encoding-msg
- (if encoded
- (format "(0%o, %d, 0x%x, file %s)"
- char char char
- (if (> (length encoded) 1)
- "..."
- (encoded-string-description encoded coding)))
- (format "(0%o, %d, 0x%x)" char char char))))
+ (if display-prop
+ (if (not (stringp display-prop))
+ (format "(0%o, %d, 0x%x, part of display \"%s\")"
+ char char char under-display)
+ (format "(0%o, %d, 0x%x, part of display \"%s\"->\"%s\")"
+ char char char under-display display-prop))
+ (if encoded
+ (format "(0%o, %d, 0x%x, file %s)"
+ char char char
+ (if (> (length encoded) 1)
+ "..."
+ (encoded-string-description encoded coding)))
+ (format "(0%o, %d, 0x%x)" char char char)))))
(if detail
;; We show the detailed information about CHAR.
(describe-char (point)))
(buffer-substring-no-properties (point) (1+ (point))))
encoding-msg pos total percent beg end col hscroll)
(message "Char: %s %s point=%d of %d (%d%%) column %d %s"
- (if (< char 256)
- (single-key-description char)
- (buffer-substring-no-properties (point) (1+ (point))))
+ (if enable-multibyte-characters
+ (if (< char 128)
+ (single-key-description char)
+ (buffer-substring-no-properties (point) (1+ (point))))
+ (single-key-description char))
encoding-msg pos total percent col hscroll))))))
\f
(defvar read-expression-map
(or (and (>= position (point-min))
(<= position (point-max)))
(if widen-automatically
- (error "Global mark position is outside accessible part of buffer")
- (widen)))
+ (widen)
+ (error "Global mark position is outside accessible part of buffer")))
(goto-char position)
(switch-to-buffer buffer)))
\f
;; at least go to end of line.
(end-of-line))
((< arg 0)
- ;; If we did not move down as far as desired,
- ;; at least go to end of line.
+ ;; If we did not move up as far as desired,
+ ;; at least go to beginning of line.
(beginning-of-line))
(t
(line-move-finish (or goal-column temporary-goal-column)
(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))
+ ;; The older method below can be erroneous if `set-goal-column' is bound
+ ;; to a sequence containing %
+ ;;(message (substitute-command-keys
+ ;;"Goal column %d (use \\[set-goal-column] with an arg to unset it)")
+ ;;goal-column)
+ (message "%s"
+ (concat
+ (format "Goal column %d " goal-column)
+ (substitute-command-keys
+ "(use \\[set-goal-column] with an arg to unset it)")))
+
+ )
nil)
\f
:group 'paren-blinking)
(defcustom blink-matching-paren-distance (* 25 1024)
- "*If non-nil, is maximum distance to search for matching open-paren."
- :type 'integer
+ "*If non-nil, maximum distance to search backwards for matching open-paren.
+If nil, search stops at the beginning of the accessible portion of the buffer."
+ :type '(choice (const nil) integer)
:group 'paren-blinking)
(defcustom blink-matching-delay 1
(defun blink-matching-open ()
"Move cursor momentarily to the beginning of the sexp before point."
(interactive)
- (and (> (point) (1+ (point-min)))
- blink-matching-paren
- ;; Verify an even number of quoting characters precede the close.
- (= 1 (logand 1 (- (point)
- (save-excursion
- (forward-char -1)
- (skip-syntax-backward "/\\")
- (point)))))
- (let* ((oldpos (point))
- (blinkpos)
- (mismatch)
- matching-paren)
- (save-excursion
- (save-restriction
- (if blink-matching-paren-distance
- (narrow-to-region (max (point-min)
- (- (point) blink-matching-paren-distance))
- oldpos))
- (condition-case ()
- (let ((parse-sexp-ignore-comments
- (and parse-sexp-ignore-comments
- (not blink-matching-paren-dont-ignore-comments))))
- (setq blinkpos (scan-sexps oldpos -1)))
- (error nil)))
- (and blinkpos
- ;; Not syntax '$'.
- (not (eq (syntax-class (syntax-after blinkpos)) 8))
- (setq matching-paren
- (let ((syntax (syntax-after blinkpos)))
- (and (consp syntax)
- (eq (syntax-class syntax) 4)
- (cdr syntax)))
- mismatch
- (or (null matching-paren)
- (/= (char-after (1- oldpos))
- matching-paren))))
- (if mismatch (setq blinkpos nil))
- (if blinkpos
- ;; Don't log messages about paren matching.
- (let (message-log-max)
- (goto-char blinkpos)
- (if (pos-visible-in-window-p)
- (and blink-matching-paren-on-screen
- (sit-for blink-matching-delay))
- (goto-char blinkpos)
- (message
- "Matches %s"
- ;; Show what precedes the open in its line, if anything.
- (if (save-excursion
- (skip-chars-backward " \t")
- (not (bolp)))
- (buffer-substring (progn (beginning-of-line) (point))
- (1+ blinkpos))
- ;; Show what follows the open in its line, if anything.
- (if (save-excursion
- (forward-char 1)
- (skip-chars-forward " \t")
- (not (eolp)))
- (buffer-substring blinkpos
- (progn (end-of-line) (point)))
- ;; Otherwise show the previous nonblank line,
- ;; if there is one.
- (if (save-excursion
- (skip-chars-backward "\n \t")
- (not (bobp)))
- (concat
- (buffer-substring (progn
+ (when (and (> (point) (point-min))
+ blink-matching-paren
+ ;; Verify an even number of quoting characters precede the close.
+ (= 1 (logand 1 (- (point)
+ (save-excursion
+ (forward-char -1)
+ (skip-syntax-backward "/\\")
+ (point))))))
+ (let* ((oldpos (point))
+ blinkpos
+ message-log-max ; Don't log messages about paren matching.
+ matching-paren
+ open-paren-line-string)
+ (save-excursion
+ (save-restriction
+ (if blink-matching-paren-distance
+ (narrow-to-region (max (point-min)
+ (- (point) blink-matching-paren-distance))
+ oldpos))
+ (condition-case ()
+ (let ((parse-sexp-ignore-comments
+ (and parse-sexp-ignore-comments
+ (not blink-matching-paren-dont-ignore-comments))))
+ (setq blinkpos (scan-sexps oldpos -1)))
+ (error nil)))
+ (and blinkpos
+ ;; Not syntax '$'.
+ (not (eq (syntax-class (syntax-after blinkpos)) 8))
+ (setq matching-paren
+ (let ((syntax (syntax-after blinkpos)))
+ (and (consp syntax)
+ (eq (syntax-class syntax) 4)
+ (cdr syntax)))))
+ (cond
+ ((or (null matching-paren)
+ (/= (char-before oldpos)
+ matching-paren))
+ (message "Mismatched parentheses"))
+ ((not blinkpos)
+ (if (not blink-matching-paren-distance)
+ (message "Unmatched parenthesis")))
+ ((pos-visible-in-window-p blinkpos)
+ ;; Matching open within window, temporarily move to blinkpos but only
+ ;; if `blink-matching-paren-on-screen' is non-nil.
+ (when blink-matching-paren-on-screen
+ (save-excursion
+ (goto-char blinkpos)
+ (sit-for blink-matching-delay))))
+ (t
+ (save-excursion
+ (goto-char blinkpos)
+ (setq open-paren-line-string
+ ;; Show what precedes the open in its line, if anything.
+ (if (save-excursion
+ (skip-chars-backward " \t")
+ (not (bolp)))
+ (buffer-substring (line-beginning-position)
+ (1+ blinkpos))
+ ;; Show what follows the open in its line, if anything.
+ (if (save-excursion
+ (forward-char 1)
+ (skip-chars-forward " \t")
+ (not (eolp)))
+ (buffer-substring blinkpos
+ (line-end-position))
+ ;; Otherwise show the previous nonblank line,
+ ;; if there is one.
+ (if (save-excursion
+ (skip-chars-backward "\n \t")
+ (not (bobp)))
+ (concat
+ (buffer-substring (progn
(skip-chars-backward "\n \t")
- (beginning-of-line)
- (point))
- (progn (end-of-line)
- (skip-chars-backward " \t")
- (point)))
- ;; Replace the newline and other whitespace with `...'.
- "..."
- (buffer-substring blinkpos (1+ blinkpos)))
- ;; There is nothing to show except the char itself.
- (buffer-substring blinkpos (1+ blinkpos))))))))
- (cond (mismatch
- (message "Mismatched parentheses"))
- ((not blink-matching-paren-distance)
- (message "Unmatched parenthesis"))))))))
+ (line-beginning-position))
+ (progn (end-of-line)
+ (skip-chars-backward " \t")
+ (point)))
+ ;; Replace the newline and other whitespace with `...'.
+ "..."
+ (buffer-substring blinkpos (1+ blinkpos)))
+ ;; There is nothing to show except the char itself.
+ (buffer-substring blinkpos (1+ blinkpos)))))))
+ (message "Matches %s"
+ (substring-no-properties open-paren-line-string))))))))
;Turned off because it makes dbx bomb out.
(setq blink-paren-function 'blink-matching-open)
With a prefix argument, set VARIABLE to VALUE buffer-locally."
(interactive
(let* ((default-var (variable-at-point))
- (var (if (symbolp default-var)
- (read-variable (format "Set variable (default %s): " default-var)
- default-var)
- (read-variable "Set variable: ")))
+ (var (if (user-variable-p default-var)
+ (read-variable (format "Set variable (default %s): " default-var)
+ default-var)
+ (read-variable "Set variable: ")))
(minibuffer-help-form '(describe-variable var))
(prop (get var 'variable-interactive))
(obsolete (car (get var 'byte-obsolete-variable)))
arg))
(read
(read-string prompt nil
- 'set-variable-value-history))))))
+ 'set-variable-value-history
+ (format "%S" (symbol-value var))))))))
(list var val current-prefix-arg)))
(and (custom-variable-p variable)
"Normal hook run at the end of setting up a completion list buffer.
When this hook is run, the current buffer is the one in which the
command to display the completion list buffer was run.
-The completion list buffer is available as the value of `standard-output'.")
+The completion list buffer is available as the value of `standard-output'.
+The common prefix substring for completion may be available as the
+value of `completion-common-substring'. See also `display-completion-list'.")
+
+
+;; Variables and faces used in `completion-setup-function'.
-;; This function goes in completion-setup-hook, so that it is called
-;; after the text of the completion list buffer is written.
(defface completions-first-difference
'((t (:inherit bold)))
"Face put on the first uncommon character in completions in *Completions* buffer."
(defvar completion-root-regexp "^/"
"Regexp to use in `completion-setup-function' to find the root directory.")
+(defvar completion-common-substring nil
+ "Common prefix substring to use in `completion-setup-function' to put faces.
+The value is set by `display-completion-list' during running `completion-setup-hook'.
+
+To put faces, `completions-first-difference' and `completions-common-part'
+into \"*Completions*\* buffer, the common prefix substring in completions is
+needed as a hint. (Minibuffer is a special case. The content of minibuffer itself
+is the substring.)")
+
+;; This function goes in completion-setup-hook, so that it is called
+;; after the text of the completion list buffer is written.
(defun completion-setup-function ()
(let ((mainbuf (current-buffer))
(mbuf-contents (minibuffer-contents)))
(funcall (get minibuffer-completion-table 'completion-base-size-function)))
(setq completion-base-size 0))))
;; Put faces on first uncommon characters and common parts.
- (when completion-base-size
+ (when (or completion-base-size completion-common-substring)
(let* ((common-string-length
- (- (length mbuf-contents) completion-base-size))
+ (if completion-base-size
+ (- (length mbuf-contents) completion-base-size)
+ (length completion-common-substring)))
(element-start (next-single-property-change
(point-min)
'mouse-face))