emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: next-error refactoring


From: Ted Zlatanov
Subject: Re: next-error refactoring
Date: Mon, 13 Sep 2004 14:56:43 -0400
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux)

On Thu, 01 Jul 2004, address@hidden wrote:

> If you want to add next-error support for more modes, you might consider
> etags, dired-do-search, find-grep-dired.

I haven't looked at etags, but here's a patch for dired.el that will
add next-error support.  That will support find-grep-dired,
dired-do-search, and all other dired-mode usages.  There's two issues:

1) by default, most users will probably not want this next-error
   support so I added a variable dired-next-error-support that's nil
   by default.  This is my conjecture so I may be wrong.

2) I am not sure of the right way to move negative distances in
   dired-mode, since not every line is a file.  I reuse the
   dired-goto-next-nontrivial-file function for forward motion and
   ignore negative distances for now.  I could write my own, but was
   wondering if something already existed for negative motion.

Please comment and I hope this can make it in Emacs eventually (it's
not ready as it is).  I am attaching a context patch.

Ted

*** /usr/src/emacs/lisp/dired.el        Wed Jul 14 18:59:08 2004
--- /home/tzz/emacs/mine/dired.el       Mon Sep 13 15:09:54 2004
***************
*** 215,220 ****
--- 215,227 ----
    :type '(alist :key-type regexp :value-type string)
    :version "21.4")
  
+ ;; should we use next-error support?
+ (defcustom dired-next-error-support nil
+   "Specifies whether Dired should support the next-error
+   framework."
+   :group 'dired
+   :type 'boolean)
+ 
  ;; Internal variables
  
  (defvar dired-marker-char ?*          ; the answer is 42
***************
*** 1397,1402 ****
--- 1404,1411 ----
        selective-display t             ; for subdirectory hiding
        mode-line-buffer-identification
        (propertized-buffer-identification "%17b"))
+   (when dired-next-error-support
+     (setq next-error-function 'dired-next-error))
    (set (make-local-variable 'revert-buffer-function)
         (function dired-revert))
    (set (make-local-variable 'buffer-stale-function)
***************
*** 1450,1455 ****
--- 1459,1490 ----
    (message "Change in Dired buffer undone.
  Actual changes in files cannot be undone by Emacs."))
  
+ (defun dired-next-error (&optional argp reset)
+   "Move to the ARGP (default 1) next match in an Dired mode buffer.
+ When RESET is given, starts from the beginning.
+ Compatibility function for \\[next-error] invocations."
+   (interactive "p")
+ 
+   (when reset
+     ;; go to beginning of buffer
+     (goto-char (point-min)))
+   
+   (dired-next-error-move-n-file-lines 
+    (prefix-numeric-value argp))
+ 
+   ;; visit file if possible
+   (when (dired-get-filename nil t)
+     (dired-find-file)))
+ 
+ (defun dired-next-error-move-n-file-lines (argp)
+   "Move ARGP file lines from the current line.
+ File lines are lines with a file listed in them.
+ ONLY SUPPORT POSITIVE MOTION FOR NOW"
+   (when (> argp 0)
+     (dotimes (n argp)
+       (forward-line 1)
+       (dired-goto-next-nontrivial-file))))
+ 
  (defun dired-next-line (arg)
    "Move down lines then position at filename.
  Optional prefix ARG says how many lines to move; default is one line."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]