gnu-emacs-sources
[Top][All Lists]
Advanced

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

Re: ;;; anything.el --- open anything


From: billclem
Subject: Re: ;;; anything.el --- open anything
Date: Mon, 30 Jul 2007 22:33:34 -0000
User-agent: G2/1.0

Hi Tamas,

"address@hidden" <address@hidden> writes:
> On Jul 30, 9:45 pm, address@hidden wrote:
>> It might be better to have
>> the exclusions done at a "lower" level (e.g. - somewhere like
>> anything-insert-match) so that the exclusions are done only once a
>> candidate is ready to be put into the anything buffer.
>
> Note that anything-candidate-transformers are invoked for async
> sources too and transformations can also be used to eliminate
> candidates from the results, not just changing their appearance.
>
> The example function anything-transform-files only colors "boring"
> files, but it could also leave them out from the results.
>
> So the infrastructure is there, it only needs to be configured.
>
> The only issue is (indicated in the TODO section):
>
> ;;   - transformations are not done properly in case of incomplete
> ;;     lines from async processes, because the incomplete part is
> ;;     already inserted into the buffer when the trasformation part
> ;;     begins
>
>
> but it may be not hard to fix, and the feature can be used
> nevertheless.

Hmm, that's interesting - I hadn't thought of using the candidate
transformer functionality (probably because there is nothing in
anything-config that relates to it and it's a more recent
feature). Ok, I modified your sample transform as follows:

(setq anything-transform-files-excludes (list "/Applications/cache/"
                                              "/.backups"
                                              "/.svn"
                                              "/CVS"
                                              "/.DS_Store"
                                              "/.cvsignore"))

(defun anything-transform-files (files)
  "Transform file candidates."

  (if anything-transform-files-excludes
      (setq files (let ((filtered-files nil))
                    (loop for file in files
                          do (if (loop for regexp in 
anything-transform-files-excludes
                                       do (if (string-match regexp file) 
(return nil))
                                       finally (return file))
                                 (setq filtered-files (append (list file) 
filtered-files)))
                          finally (return filtered-files)))))

  (let ((boring-file-regexp
         (concat "\\(?:" (regexp-opt completion-ignored-extensions) "\
\)\\'")))
    (mapcar (lambda (file)
              ;; Add shadow face property to boring files.
              (let ((face (if (facep 'file-name-shadow)
                              'file-name-shadow
                            ;; fall back to default on XEmacs
                            'default)))
                (if (string-match boring-file-regexp file)
                    (setq file (propertize file 'face face))))

              ;; replace path of HOME directory in paths with the
string
              ;; <home>
              (let ((home (replace-regexp-in-string "\\\\" "/" ;
stupid Windows...
                                                    (getenv "HOME"))))
                (if (string-match home file)
                    (cons (replace-match "<home>" nil nil file) file)
                  file)))
            files)))

This substantially reduces the number of "false" matches in the
"locate" and "mdfind" results. However, another problem (in addition
to the ones you mentioned) with doing the exclusions in a candidate
transformer function is that the anything-candidate-number-limit has
already been checked prior to the transformer function being
called. Therefore, the number of matches that shows up in the anything
buffer can be significantly reduced by my code. For example, I have a
lot of "matches" in the ".backups" folder and the
"/Application/cache/" folder and the ".svn" folder for files that are
in a development directory. When I do an anything search without my
code, I get 50 matches displayed under the "locate" category. However,
with my code added to the anything-transform-files function, I only
get 3 matches displayed under the "locate" category because so many of
the previous matches are now being excluded.

--
Bill Clementson



reply via email to

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