1 ;;; anything-match-plugin.el --- Humane match plug-in for anything
2 ;; $Id: anything-match-plugin.el,v 1.27 2010-03-24 11:11:28 rubikitch Exp $
4 ;; Copyright (C) 2008 rubikitch
6 ;; Author: rubikitch <rubikitch@ruby-lang.org>
7 ;; Keywords: anything, matching
8 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/anything-match-plugin.el
10 ;; This file is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This file is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 ;; Change anything.el matching algorithm humanely.
28 ;; It gives anything.el search refinement functionality.
29 ;; exact match -> prefix match -> multiple regexp match
33 ;; Below are complete command list:
36 ;;; Customizable Options:
38 ;; Below are customizable option list:
40 ;; `anything-grep-candidates-fast-directory-regexp'
41 ;; *Directory regexp where a RAM disk (or tmpfs) is mounted.
44 ;; A query of multiple regexp match is space-delimited string.
45 ;; Anything displays candidates which matches all the regexps.
46 ;; A regexp with "!" prefix means not matching the regexp.
47 ;; To include spaces to a regexp, prefix "\" before space,
48 ;; it is controlled by `anything-mp-space-regexp' variable.
50 ;; If multiple regexps are specified, first one also tries to match the source name.
51 ;; If you want to disable this feature, evaluate
52 ;; (setq anything-mp-match-source-name nil) .
54 ;; This file highlights patterns like `occur'. Note that patterns
55 ;; longer than `anything-mp-highlight-threshold' are highlighted. And
56 ;; region out of screen is highlighted after
57 ;; `anything-mp-highlight-delay' seconds.
59 ;; Highlight in Emacs is time-consuming process for slow computers. To
60 ;; disable it is to set nil to `anything-mp-highlight-delay'.
62 ;; Just require it to use.
66 ;; $Log: anything-match-plugin.el,v $
67 ;; Revision 1.27 2010-03-24 11:11:28 rubikitch
68 ;; Added :group keyword to `defface anything-match'
70 ;; Revision 1.26 2010/03/24 10:48:55 rubikitch
71 ;; grep-candidates plug-in: document / imply `delayed' attribute
73 ;; Revision 1.25 2010/03/24 10:38:48 rubikitch
74 ;; grep-candidates plugin: grep-candidates attribute can also accept variable/function name.
76 ;; Revision 1.24 2010/03/22 09:01:22 rubikitch
77 ;; grep-candidates plugin released
79 ;; Revision 1.23 2010/03/22 08:02:11 rubikitch
80 ;; grep-candidates plugin prototype
82 ;; Revision 1.22 2009/03/03 10:21:45 rubikitch
83 ;; * Remove highlight.el dependency.
84 ;; * Very faster highlight.
86 ;; Revision 1.21 2009/03/03 08:51:23 rubikitch
87 ;; New variable: `anything-mp-highlight-threshold'
89 ;; Revision 1.20 2009/03/03 07:29:24 rubikitch
92 ;; Revision 1.19 2008/09/08 06:58:59 rubikitch
93 ;; changed default `anything-mp-space-regexp' to "[\\ ] "
95 ;; Revision 1.18 2008/09/07 12:09:01 rubikitch
96 ;; *** empty log message ***
98 ;; Revision 1.17 2008/09/07 07:48:12 rubikitch
100 ;; Multiple regexp match with regexp negation.
102 ;; Revision 1.16 2008/09/07 06:58:11 rubikitch
103 ;; Added mp-3p match: permutation with prefix match
105 ;; Revision 1.15 2008/09/07 05:23:07 rubikitch
106 ;; New variable: `anything-mp-space-regexp'
108 ;; Revision 1.14 2008/09/03 03:33:09 rubikitch
109 ;; anything-exact-*, anything-prefix-*: memoize
111 ;; Revision 1.13 2008/09/02 10:56:50 rubikitch
112 ;; anything-mp-3-*: MUCH MUCH FASTER
115 ;; Revision 1.12 2008/09/01 13:41:57 rubikitch
116 ;; search functions for search-from-end
118 ;; Revision 1.11 2008/08/24 20:40:27 rubikitch
119 ;; prevent the unit test from being byte-compiled.
121 ;; Revision 1.10 2008/08/24 17:48:53 rubikitch
124 ;; Revision 1.9 2008/08/24 08:23:16 rubikitch
125 ;; Rename `anything-candidates-buffer' -> `anything-candidate-buffer'
127 ;; Revision 1.8 2008/08/22 21:25:44 rubikitch
128 ;; *** empty log message ***
130 ;; Revision 1.7 2008/08/22 21:17:58 rubikitch
131 ;; exact, prefix match: faster
133 ;; Revision 1.6 2008/08/22 19:40:22 rubikitch
134 ;; exact -> prefix -> mp-3 by default because of speed
136 ;; Revision 1.5 2008/08/22 19:04:53 rubikitch
139 ;; Revision 1.4 2008/08/20 00:10:15 rubikitch
140 ;; *** empty log message ***
142 ;; Revision 1.3 2008/08/19 23:30:39 rubikitch
143 ;; exact match support
145 ;; Revision 1.2 2008/08/19 23:02:29 rubikitch
146 ;; candidates-in-buffer hack
148 ;; Revision 1.1 2008/08/19 19:45:11 rubikitch
158 (defcustom anything-grep-candidates-fast-directory-regexp nil
159 "*Directory regexp where a RAM disk (or tmpfs) is mounted.
161 If non-nil, grep-candidates plugin gets faster because it uses
162 grep as synchronous process.
164 ex. (setq anything-grep-candidates-fast-directory-regexp \"^/tmp/\")"
168 ;;;; multiple patterns
169 (defvar anything-use-multiple-patterns t
170 "If non-nil, enable anything-use-multiple-patterns.")
171 (defvar anything-mp-space-regexp
"[\\ ] "
172 "Regexp to represent space itself in multiple regexp match.")
173 (defvar anything-mp-match-source-name t
174 "If non-nil, first query in space-delimited pattern try to match the source name.
175 It needs at least two queries.
176 For example, to list candidats of \"foo\" source, input pattern as \"foo .\".")
178 (defun amp-mp-make-regexps (pattern)
179 (if (string= pattern
"") '("")
180 (loop for s in
(split-string
181 (replace-regexp-in-string anything-mp-space-regexp
182 "\000\000" pattern
) " " t
)
183 collect
(replace-regexp-in-string "\000\000" " " s
))))
185 (defun amp-mp-1-make-regexp (pattern)
186 (mapconcat 'identity
(amp-mp-make-regexps pattern
) ".*"))
188 (defmacro amp-define-memoizer
(prefix pattern-expr
)
189 (let ((pattern-str (intern (concat prefix
"pattern-str")))
190 (pattern-real (intern (concat prefix
"pattern-real")))
191 (get-pattern (intern (concat prefix
"get-pattern"))))
193 (defvar ,pattern-str nil
)
194 (defvar ,pattern-real nil
)
195 (defsubst ,get-pattern
(pattern)
196 (unless (equal pattern
,pattern-str
)
197 (setq ,pattern-str pattern
198 ,pattern-real
,pattern-expr
))
201 (defmacro amp-define
(prefix pattern-expr
)
202 (let ((get-pattern (intern (concat prefix
"get-pattern")))
203 (match (intern (concat prefix
"match")))
204 (search (intern (concat prefix
"search")))
205 (search-backward (intern (concat prefix
"search-backward"))))
207 (amp-define-memoizer ,prefix
,pattern-expr
)
208 (defun* ,match
(str &optional
(pattern anything-pattern
))
209 (string-match (,get-pattern pattern
) str
))
210 (defun ,search
(pattern &rest ignore
)
211 (re-search-forward (,get-pattern pattern
) nil t
))
212 (defun ,search-backward
(pattern &rest ignore
)
213 (re-search-backward (,get-pattern pattern
) nil t
)))))
216 ;(amp-define "anything-exact-" (concat (anything-prefix-get-pattern pattern) "$"))
217 (amp-define-memoizer "anything-exact-" (concat "\n" pattern
"\n"))
218 (defun anything-exact-match (str &optional pattern
)
219 (string= str
(or pattern anything-pattern
)))
220 (defun anything-exact-search (pattern &rest ignore
)
221 (and (search-forward (anything-exact-get-pattern pattern
) nil t
)
223 (defun anything-exact-search-backward (pattern &rest ignore
)
224 (and (search-backward (anything-exact-get-pattern pattern
) nil t
)
227 ;;(amp-define "anything-prefix-" (concat "^" (regexp-quote pattern)))
228 (amp-define-memoizer "anything-prefix-" (concat "\n" pattern
))
229 (defun anything-prefix-match (str &optional pattern
)
230 (setq pattern
(or pattern anything-pattern
))
231 (let ((len (length pattern
)))
232 (and (<= len
(length str
))
233 (string= (substring str
0 len
) pattern
))))
234 (defun anything-prefix-search (pattern &rest ignore
)
235 (search-forward (anything-prefix-get-pattern pattern
) nil t
))
236 (defun anything-prefix-search-backward (pattern &rest ignore
)
237 (and (search-backward (anything-prefix-get-pattern pattern
) nil t
)
239 ;; multiple regexp patterns 1 (order is preserved / prefix)
240 (amp-define "anything-mp-1-" (concat "^" (amp-mp-1-make-regexp pattern
)))
241 ;; multiple regexp patterns 2 (order is preserved / partial)
242 (amp-define "anything-mp-2-" (concat "^.+" (amp-mp-1-make-regexp pattern
)))
244 ;;;; multiple regexp patterns 3 (permutation)
245 (defvar anything-mp-3-pattern-str nil
)
246 (defvar anything-mp-3-pattern-list nil
)
247 (defsubst anything-mp-3-get-patterns
(pattern)
248 (unless (equal pattern anything-mp-3-pattern-str
)
249 (setq anything-mp-3-pattern-str pattern
250 anything-mp-3-pattern-list
251 (anything-mp-3-get-patterns-internal pattern
)))
252 anything-mp-3-pattern-list
)
253 (defun anything-mp-3-get-patterns-internal (pattern)
254 (unless (string= pattern
"")
255 (loop for pat in
(amp-mp-make-regexps pattern
)
256 collect
(if (string= "!" (substring pat
0 1))
257 (cons 'not
(substring pat
1))
258 (cons 'identity pat
)))))
259 (defun anything-mp-handle-source-name-maybe (pattern self else
)
260 (when (stringp pattern
)
261 (setq pattern
(anything-mp-3-get-patterns pattern
)))
262 ;; PATTERN is list of (pred . re) now.
264 (destructuring-bind ((first-pred . first-re
) . rest
) pattern
265 (if (and anything-mp-match-source-name
266 (stringp anything-source-name
)
267 (eq 'identity first-pred
))
268 (let (anything-mp-match-source-name)
269 (or (and (string-match first-re anything-source-name
)
271 (funcall self pattern
)))
274 (defun* anything-mp-3-match
(str &optional
(pattern anything-pattern
))
275 (anything-mp-handle-source-name-maybe
276 pattern
(apply-partially 'anything-mp-3-match str
)
278 (loop for
(pred . re
) in pattern
279 always
(funcall pred
(string-match re str
))))))
281 (defmacro anything-mp-3-search-base
(searchfn1 searchfn2 b e
)
282 `(loop with pat
= (if (stringp pattern
)
283 (anything-mp-3-get-patterns pattern
)
285 while
(,searchfn1
(or (cdar pat
) "") nil t
)
286 for bol
= (point-at-bol)
287 for eol
= (point-at-eol)
289 for
(pred . s
) in
(cdr pat
)
290 always
(progn (goto-char ,b
)
291 (funcall pred
(,searchfn2 s
,e t
))))
292 do
(goto-char ,e
) (return t
)
295 finally
(return nil
)))
297 (defun anything-mp-3-search (pattern &rest ignore
)
298 (anything-mp-handle-source-name-maybe
299 pattern
'anything-mp-3-search
300 (lambda () (anything-mp-3-search-base
301 re-search-forward re-search-forward bol eol
))))
302 (defun anything-mp-3-search-backward (pattern &rest ignore
)
303 (anything-mp-handle-source-name-maybe
304 pattern
'anything-mp-3-search-backward
305 (lambda () (anything-mp-3-search-base
306 re-search-backward re-search-backward eol bol
))))
307 ;; mp-3p- (multiple regexp pattern 3 with prefix search)
308 (defun* anything-mp-3p-match
(str &optional
(pattern anything-pattern
))
309 (anything-mp-handle-source-name-maybe
310 pattern
(apply-partially 'anything-mp-3p-match str
)
312 (declare (special first-pred first-re rest
))
313 (and (funcall first-pred
(anything-prefix-match str first-re
))
314 (loop for
(pred . re
) in rest
315 always
(funcall pred
(string-match re str
)))))))
317 (defun anything-mp-3p-search (pattern &rest ignore
)
318 (anything-mp-handle-source-name-maybe
319 pattern
'anything-mp-3p-search
320 (lambda () (anything-mp-3-search-base
321 anything-prefix-search re-search-forward bol eol
))))
323 (defun anything-mp-3p-search-backward (pattern &rest ignore
)
324 (anything-mp-handle-source-name-maybe
325 pattern
'anything-mp-3p-search-backward
326 (lambda () (anything-mp-3-search-base
327 anything-prefix-search-backward re-search-backward eol bol
))))
329 ;;;; Highlight matches
330 (defface anything-match
331 '((t (:inherit match
)))
332 "Face used to highlight matches."
335 (defvar anything-mp-highlight-delay
0.7
336 "Highlight matches with `anything-match' face after this many seconds.
337 If nil, no highlight. ")
339 (defvar anything-mp-highlight-threshold
2
340 "Minimum length of pattern to highlight.
341 The smaller this value is, the slower highlight is.")
343 (defun anything-mp-highlight-match ()
344 "Highlight matches after `anything-mp-highlight-delay' seconds."
345 (when (and anything-mp-highlight-delay
346 (not (string= anything-pattern
"")))
347 (anything-mp-highlight-match-internal (window-end (anything-window)))
348 (run-with-idle-timer anything-mp-highlight-delay nil
349 'anything-mp-highlight-match-internal
350 (with-current-buffer anything-buffer
(point-max)))))
351 (add-hook 'anything-update-hook
'anything-mp-highlight-match
)
353 (defun anything-mp-highlight-region (start end regexp face
)
357 (while (and (setq me
(re-search-forward regexp nil t
))
359 (< 0 (- (match-end 0) (match-beginning 0))))
360 (put-text-property (match-beginning 0) me
'face face
)))))
362 (defun* anything-mp-highlight-match-internal
(end)
363 (when (anything-window)
364 (set-buffer anything-buffer
)
365 (let ((requote (regexp-quote anything-pattern
)))
366 (when (>= (length requote
) anything-mp-highlight-threshold
)
367 (anything-mp-highlight-region (point-min) end
368 requote
'anything-match
)))
369 (loop for
(pred . re
) in
(anything-mp-3-get-patterns anything-pattern
)
370 when
(and (eq pred
'identity
)
371 (>= (length re
) anything-mp-highlight-threshold
))
373 (anything-mp-highlight-region (point-min) end re
'anything-match
))))
376 (defvar anything-mp-default-match-functions
377 '(anything-exact-match anything-mp-3p-match anything-mp-3-match
))
378 (defvar anything-mp-default-search-functions
379 '(anything-exact-search anything-mp-3p-search anything-mp-3-search
))
380 (defvar anything-mp-default-search-backward-functions
381 '(anything-exact-search-backward anything-mp-3p-search-backward
382 anything-mp-3-search-backward
))
383 (defun anything-compile-source--match-plugin (source)
384 (let ((searchers (if (assoc 'search-from-end source
)
385 anything-mp-default-search-backward-functions
386 anything-mp-default-search-functions
)))
387 `(,(if (or (assoc 'candidates-in-buffer source
)
388 (equal '(identity) (assoc-default 'match source
)))
390 `(match ,@anything-mp-default-match-functions
391 ,@(assoc-default 'match source
)))
393 ,@(assoc-default 'search source
))
396 (add-to-list 'anything-compile-source-functions
'anything-compile-source--match-plugin t
)
398 ;;;; grep-candidates plug-in
399 (defun agp-candidates (&optional filter
)
400 "Normal version of grep-candidates candidates function.
401 Grep is run by asynchronous process."
402 (start-process-shell-command
403 "anything-grep-candidates" nil
404 (agp-command-line-2 filter
(anything-attr-defined 'search-from-end
))))
405 (defun agp-candidates-synchronous-grep (&optional filter
)
406 "Faster version of grep-candidates candidates function.
407 Grep is run by synchronous process.
408 It is faster when candidate files are in ramdisk."
410 (shell-command-to-string
411 (agp-command-line-2 filter
(anything-attr-defined 'search-from-end
)))
413 (defun agp-candidates-synchronous-grep--direct-insert-match (&optional filter
)
414 "[EXPERIMENTAL]Fastest version of grep-candidates candidates function at the cost of absense of transformers.
415 Grep is run by synchronous process.
416 It is faster when candidate files are in ramdisk.
418 If (direct-insert-match) is in the source, this function is used."
419 (with-current-buffer (anything-candidate-buffer 'global
)
420 (call-process-shell-command
421 (agp-command-line-2 filter
(anything-attr-defined 'search-from-end
))
424 (defun agp-command-line (query files
&optional limit filter search-from-end
)
425 "Build command line used by grep-candidates from QUERY, FILES, LIMIT, and FILTER."
426 (let ((allfiles (mapconcat (lambda (f) (shell-quote-argument (expand-file-name f
)))
429 (when search-from-end
430 (insert "tac " allfiles
))
431 (if (string= query
"")
432 (unless search-from-end
433 (insert "cat " allfiles
))
434 (when search-from-end
(insert " | "))
435 (loop for
(flag . re
) in
(anything-mp-3-get-patterns-internal query
)
438 (setq re
(replace-regexp-in-string "^-" "\\-" re
))
439 (unless (zerop i
) (insert " | "))
441 (if (eq flag
'identity
) "" "-v ")
442 (shell-quote-argument re
))
443 (when (and (not search-from-end
) (zerop i
))
444 (insert " " allfiles
))))
446 (when limit
(insert (format " | head -n %d" limit
)))
447 (when filter
(insert " | " filter
))
449 (defun agp-command-line-2 (filter &optional search-from-end
)
450 "Build command line used by grep-candidates from FILTER and current source."
453 (anything-mklist (anything-interpret-value (anything-attr 'grep-candidates
)))
454 (anything-candidate-number-limit (anything-get-current-source))
455 filter search-from-end
))
456 (defun anything-compile-source--grep-candidates (source)
457 (anything-aif (assoc-default 'grep-candidates source
)
460 (let ((use-fast-directory
461 (and anything-grep-candidates-fast-directory-regexp
463 anything-grep-candidates-fast-directory-regexp
464 (or (car (anything-mklist (anything-interpret-value it
))) "")))))
465 (cond ((not (anything-interpret-value it
)) nil
)
466 ((and use-fast-directory
(assq 'direct-insert-match source
))
467 (anything-log "fastest version (use-fast-directory and direct-insert-match)")
468 `((candidates . agp-candidates-synchronous-grep--direct-insert-match
)
472 (anything-log "faster version (use-fast-directory)")
473 `((candidates . agp-candidates-synchronous-grep
)
477 (anything-log "normal version")
478 '((candidates . agp-candidates
)
481 (add-to-list 'anything-compile-source-functions
'anything-compile-source--grep-candidates
)
483 (anything-document-attribute 'grep-candidates
"grep-candidates plug-in"
484 "grep-candidates plug-in provides anything-match-plugin.el feature with grep and head program.
485 It is MUCH FASTER than normal match-plugin to search from vary large (> 1MB) candidates.
486 Make sure to install these programs.
488 It expands `candidates' and `delayed' attributes.
490 `grep-candidates' attribute accepts a filename or list of filename.
491 It also accepts 0-argument function name or variable name.")
493 ;; (anything '(((name . "grep-test") (grep-candidates . "~/.emacs.el") (action . message))))
494 ;; (let ((a "~/.emacs.el")) (anything '(((name . "grep-test") (grep-candidates . a) (action . message) (delayed)))))
495 ;; (let ((a "~/.emacs.el")) (anything '(((name . "grep-test") (grep-candidates . (lambda () a)) (action . message) (delayed)))))
496 ;; (anything '(((name . "grep-test") (grep-candidates . "~/.emacs.el") (action . message) (delayed) (candidate-number-limit . 2))))
497 ;; (let ((anything-candidate-number-limit 2)) (anything '(((name . "grep-test") (grep-candidates . "~/.emacs.el") (action . message) (delayed)))))
500 (unless (fboundp 'apply-partially
)
501 (defun apply-partially (fun &rest args
)
502 "Return a function that is a partial application of FUN to ARGS.
503 ARGS is a list of the first N arguments to pass to FUN.
504 The result is a new function which does the same as FUN, except that
505 the first N arguments are fixed at the values with which this function
507 (lexical-let ((fun fun
) (args1 args
))
508 (lambda (&rest args2
) (apply fun
(append args1 args2
))))))
511 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el")
512 ;; (install-elisp "http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el")
514 (when (fboundp 'expectations
)
516 (desc "amp-mp-make-regexps")
518 (amp-mp-make-regexps ""))
519 (expect '("foo" "bar")
520 (amp-mp-make-regexps "foo bar"))
521 (expect '("foo" "bar")
522 (amp-mp-make-regexps " foo bar"))
523 (expect '("foo" "bar")
524 (amp-mp-make-regexps " foo bar "))
525 (expect '("foo bar" "baz")
526 (let ((anything-mp-space-regexp "\\\\ "))
527 (amp-mp-make-regexps "foo\\ bar baz")))
528 (desc "anything-mp-3-get-patterns-internal")
529 (expect '((identity .
"foo"))
530 (anything-mp-3-get-patterns-internal "foo"))
531 (expect '((identity .
"foo") (identity .
"bar"))
532 (anything-mp-3-get-patterns-internal "foo bar"))
533 (expect '((identity .
"foo") (not .
"bar"))
534 (anything-mp-3-get-patterns-internal "foo !bar"))
535 (desc "agp-command-line")
536 (expect "grep -ih foo /f1"
537 (agp-command-line "foo" '("/f1")))
538 (expect "grep -ih foo /f1 | grep -ih bar"
539 (agp-command-line "foo bar" '("/f1")))
540 (expect "grep -ih foo /f1 | grep -ih -v bar"
541 (agp-command-line "foo !bar" '("/f1")))
542 (expect "grep -ih foo /f1 /f\\ 2 | grep -ih -v bar | grep -ih baz"
543 (agp-command-line "foo !bar baz" '("/f1" "/f 2")))
544 (expect (concat "grep -ih foo " (expand-file-name "~/.emacs.el"))
545 (agp-command-line "foo" '("~/.emacs.el")))
546 (expect "grep -ih f\\ o /f\\ 1"
547 (agp-command-line "f o" '("/f 1")))
548 (expect "grep -ih foo /f1 | head -n 5"
549 (agp-command-line "foo" '("/f1") 5))
550 (expect "grep -ih foo /f1 | head -n 5 | nkf -w"
551 (agp-command-line "foo" '("/f1") 5 "nkf -w"))
552 (expect "cat /f1 | head -n 5 | nkf -w"
553 (agp-command-line "" '("/f1") 5 "nkf -w"))
554 (expect "tac /f1 | grep -ih foo"
555 (agp-command-line "foo" '("/f1") nil nil t
))
556 (expect "tac /f1 | grep -ih foo | head -n 5 | nkf -w"
557 (agp-command-line "foo" '("/f1") 5 "nkf -w" t
))
558 (expect "tac /f1 | head -n 5 | nkf -w"
559 (agp-command-line "" '("/f1") 5 "nkf -w" t
))
560 (desc "anything-exact-match")
562 (anything-exact-match "thunder" "thunder"))
564 (anything-exact-match "thunder" "fire"))
565 (desc "anything-exact-search")
568 (insert "fire\nthunder\n")
570 (anything-exact-search "thunder" nil t
)))
573 (insert "\nfire\nthunder\n")
575 (anything-exact-search "fire" nil t
)))
576 (desc "anything-prefix-search")
579 (insert "fire\nthunder\n")
580 (goto-char (point-min))
581 (anything-prefix-search "thund" nil t
)))
584 (insert "fire\nthunder\n")
585 (goto-char (point-min))
586 (anything-prefix-search "hund" nil t
)))
587 (desc "anything-prefix-search-backward")
590 (insert "fire\nthunder\n")
591 (goto-char (point-max))
592 (anything-prefix-search-backward "thund" nil t
)))
595 (insert "fire\nthunder\n")
596 (goto-char (point-max))
597 (anything-prefix-search-backward "hund" nil t
)))
598 (desc "amp-mp-1-make-regexp")
600 (amp-mp-1-make-regexp "a b"))
602 (let ((anything-mp-space-regexp "\\\\ "))
603 (amp-mp-1-make-regexp "a\\ b")))
605 (let ((anything-mp-space-regexp "\\\\ "))
606 (amp-mp-1-make-regexp "a b\\ c")))
608 (amp-mp-1-make-regexp ""))
609 (desc "anything-mp-1-search")
612 (insert "fire\nthunder\n")
614 (anything-mp-1-search "th+ r" nil t
)))
615 (desc "anything-mp-2-search")
618 (insert "fire\nthunder\n")
620 (anything-mp-2-search "h+ r" nil t
)))
623 (insert "fire\nthunder\n")
625 (anything-mp-2-search "th+ r" nil t
)))
626 (desc "anything-mp-3-search")
629 (insert "fire\nthunder\n")
631 (anything-mp-3-search "h+ r" nil t
)))
634 (insert "fire\nthunder\n")
636 (anything-mp-3-search "th+ r" nil t
)))
639 (insert "fire\nthunder\n")
641 (anything-mp-3-search "r th+" nil t
)))
644 (insert "fire\nthunder\n")
646 (anything-mp-3-search "under hue" nil t
)))
649 (insert "fire\nthunder\n")
651 (anything-mp-3-search "r th+ n" nil t
)))
652 (desc "anything-mp-3-search")
655 (insert "fire\nthunder\n")
657 (anything-mp-3-search "th der" nil t
)))
660 (insert "fire\nthunder\n")
662 (anything-mp-3-search "th ders" nil t
)))
663 (desc "anything-mp-3-search not")
666 (insert "threshold\nthunder\n")
668 (anything-mp-3-search "h !der" nil t
)))
671 (insert "threshold\nthunder\n")
673 (anything-mp-3-search "th !der" nil t
)))
674 (desc "anything-mp-3p-search")
677 (insert "fire\nthunder\n")
679 (anything-mp-3p-search "th der" nil t
)))
682 (insert "fire\nthunder\n")
684 (anything-mp-3p-search "h ders" nil t
)))
685 (desc "anything-mp-3p-search not")
688 (insert "\nthreshold\nthunder\n")
690 (anything-mp-3p-search "th !der" nil t
)))
693 (insert "threshold\nthunder\n")
695 (anything-mp-3p-search "h !der" nil t
)))
696 (desc "anything-mp-3-search-backward")
699 (insert "fire\nthunder\n")
700 (goto-char (point-max))
701 (anything-mp-3-search-backward "h der" nil t
)))
704 (insert "fire\nthunder\n")
705 (goto-char (point-max))
706 (anything-mp-3-search-backward "th ders" nil t
)))
707 (desc "anything-mp-3-search-backward not")
710 (insert "threshold\nthunder\n")
711 (goto-char (point-max))
712 (anything-mp-3-search-backward "h !der" nil t
)))
715 (insert "threshold\nthunder\n")
716 (goto-char (point-max))
717 (anything-mp-3-search-backward "th !der" nil t
)))
718 (desc "anything-mp-3p-search-backward")
721 (insert "fire\nthunder\n")
722 (goto-char (point-max))
723 (anything-mp-3p-search-backward "th der" nil t
)))
726 (insert "fire\nthunder\n")
727 (goto-char (point-max))
728 (anything-mp-3p-search-backward "h der" nil t
)))
729 (desc "anything-mp-3p-search-backward not")
732 (insert "\nthreshold\nthunder\n")
733 (goto-char (point-max))
734 (anything-mp-3p-search-backward "th !der" nil t
)))
737 (insert "threshold\nthunder\n")
738 (goto-char (point-max))
739 (anything-mp-3p-search-backward "h !der" nil t
)))
740 (desc "anything-mp-1-match")
742 (anything-mp-1-match "thunder" "th+ r"))
743 (desc "anything-mp-2-match")
745 (anything-mp-2-match "thunder" "h+ r"))
747 (anything-mp-2-match "thunder" "th+ r"))
748 (desc "anything-mp-3-match")
750 (anything-mp-3-match "thunder" "h+ r"))
752 (anything-mp-3-match "thunder" "th+ r"))
754 (anything-mp-3-match "thunder" "r th+"))
756 (anything-mp-3-match "thunder" "under hue"))
758 (anything-mp-3-match "thunder" "r th+ n"))
759 (desc "anything-mp-3-match not")
761 (anything-mp-3-match "threshold" "th !der"))
762 (desc "anything-prefix-match")
764 (anything-prefix-match "fobar" "fo"))
766 (anything-prefix-match "xfobar" "fo"))
768 (desc "anything-mp-3-match")
770 (anything-mp-3-match "thunder" "h der"))
772 (anything-mp-3-match "thunder" "h ders"))
773 (desc "anything-mp-3p-match")
775 (anything-mp-3p-match "thunder" "th der"))
777 (anything-mp-3p-match "thunder" "h der"))
778 (desc "anything-mp-3p-match not")
780 (anything-mp-3p-match "threshold" "th !der"))
782 (anything-mp-3p-match "threshold" "h !der"))
783 (desc "with identity match")
785 (assoc-default 'match
786 (car (anything-compile-sources
788 (candidates-in-buffer)))
789 '(anything-compile-source--candidates-in-buffer
790 anything-compile-source--match-plugin
)))))
792 (assoc-default 'match
793 (car (anything-compile-sources
796 '(anything-compile-source--match-plugin)))))
798 (expect '(("FOO" ("thunder")))
799 (anything-test-candidates '(((name .
"FOO")
800 (candidates "fire" "thunder")))
802 '(anything-compile-source--match-plugin)))
803 (expect '(("FOO" ("one two")))
804 (let ((anything-mp-space-regexp "\\\\ "))
805 (anything-test-candidates '(((name .
"FOO")
806 (candidates "one two" "three four")))
808 '(anything-compile-source--match-plugin))))
809 (expect '(("FOO" ("one two")))
810 (let ((anything-mp-space-regexp " "))
811 (anything-test-candidates '(((name .
"FOO")
812 (candidates "one two" "three four")))
814 '(anything-compile-source--match-plugin))))
815 (expect '(("FOO" ("thunder")))
816 (anything-test-candidates '(((name .
"FOO")
819 (with-current-buffer (anything-candidate-buffer 'global
)
820 (insert "fire\nthunder\nthanks\n"))))
821 (candidates-in-buffer)))
823 '(anything-compile-source--candidates-in-buffer
824 anything-compile-source--match-plugin
)))
825 (expect '(("FOO" ("foo" "foobar")))
826 (anything-test-candidates '(((name .
"FOO")
827 (candidates "foobar" "foo")))
829 '(anything-compile-source--match-plugin)))
830 (expect '(("FOO" ("foo" "foobar")))
831 (anything-test-candidates '(((name .
"FOO")
834 (with-current-buffer (anything-candidate-buffer 'global
)
835 (insert "foobar\nfoo\n"))))
836 (candidates-in-buffer)))
838 '(anything-compile-source--candidates-in-buffer
839 anything-compile-source--match-plugin
)))
840 (expect '(("FOO" ("foo")))
841 (anything-test-candidates '(((name .
"FOO")
844 (with-current-buffer (anything-candidate-buffer 'global
)
846 (candidates-in-buffer)))
848 '(anything-compile-source--candidates-in-buffer
849 anything-compile-source--match-plugin
)))
850 (expect '(("FOO" ("foo")))
851 (anything-test-candidates '(((name .
"FOO")
854 (with-current-buffer (anything-candidate-buffer 'global
)
855 (insert "bar\nfoo\ntest\n"))))
856 (candidates-in-buffer)))
858 '(anything-compile-source--candidates-in-buffer
859 anything-compile-source--match-plugin
)))
860 (expect '(("FOO" ("foobar" "foo")))
861 (anything-test-candidates '(((name .
"FOO")
864 (with-current-buffer (anything-candidate-buffer 'global
)
865 (insert "foobar\nfoo\n"))))
866 (candidates-in-buffer)))
868 '(anything-compile-source--candidates-in-buffer
869 anything-compile-source--match-plugin
)))
870 (expect '(("FOO" ("foo" "foobar")))
871 (anything-test-candidates '(((name .
"FOO")
874 (with-current-buffer (anything-candidate-buffer 'global
)
875 (insert "foobar\nfoo\n"))))
876 (candidates-in-buffer)
879 '(anything-compile-source--candidates-in-buffer
880 anything-compile-source--match-plugin
)))
881 (expect '(("FOO" ("elisp" "elp")))
882 (anything-test-candidates '(((name .
"FOO")
885 (with-current-buffer (anything-candidate-buffer 'global
)
886 (insert "elp\nelisp\n"))))
887 (candidates-in-buffer)
890 '(anything-compile-source--candidates-in-buffer
891 anything-compile-source--match-plugin
)))
892 (expect '(("FOO" ("elisp" )))
893 (anything-test-candidates '(((name .
"FOO")
896 (with-current-buffer (anything-candidate-buffer 'global
)
897 (insert "elp\nelisp\n"))))
898 (candidates-in-buffer)
901 '(anything-compile-source--candidates-in-buffer
902 anything-compile-source--match-plugin
)))
903 ;; prefix multi -> multi
904 (expect '(("FOO" ("elisp-info" "info.el")))
905 (anything-test-candidates '(((name .
"FOO")
908 (with-current-buffer (anything-candidate-buffer 'global
)
909 (insert "info.el\nelisp-info\n"))))
910 (candidates-in-buffer)
913 '(anything-compile-source--candidates-in-buffer
914 anything-compile-source--match-plugin
)))
916 (expect '(("FOO" ("info.el")))
917 (anything-test-candidates '(((name .
"FOO")
920 (with-current-buffer (anything-candidate-buffer 'global
)
921 (insert "info.el\nelisp-info\n"))))
922 (candidates-in-buffer)
925 '(anything-compile-source--candidates-in-buffer
926 anything-compile-source--match-plugin
)))
927 ;; anything-mp-match-source-name
928 (expect '(("SourceName" ("foo")))
929 (let ((anything-mp-match-source-name t
))
930 (anything-test-candidates '(((name .
"SourceName")
931 (candidates "foo" "bar")))
933 '(anything-compile-source--match-plugin))))
934 (expect '(("SourceName cib" ("foo")))
935 (let ((anything-mp-match-source-name t
))
936 (anything-test-candidates '(((name .
"SourceName cib")
939 (with-current-buffer (anything-candidate-buffer 'global
)
940 (insert "foo\nbar\n"))))
941 (candidates-in-buffer)))
943 '(anything-compile-source--candidates-in-buffer
944 anything-compile-source--match-plugin
))))
945 (expect '(("SourceName cib search-from-end" ("bar")))
946 (let ((anything-mp-match-source-name t
))
947 (anything-test-candidates '(((name .
"SourceName cib search-from-end")
950 (with-current-buffer (anything-candidate-buffer 'global
)
951 (insert "foo\nbar\n"))))
953 (candidates-in-buffer)))
955 '(anything-compile-source--candidates-in-buffer
956 anything-compile-source--match-plugin
))))
957 (expect '(("SourceName" ("foo" "bar")))
958 (let ((anything-mp-match-source-name t
))
959 (anything-test-candidates '(((name .
"SourceName")
960 (candidates "foo" "bar")))
962 '(anything-compile-source--match-plugin))))
963 (expect '(("SourceName cib" ("foo" "bar")))
964 (let ((anything-mp-match-source-name t
))
965 (anything-test-candidates '(((name .
"SourceName cib")
968 (with-current-buffer (anything-candidate-buffer 'global
)
969 (insert "foo\nbar\n"))))
970 (candidates-in-buffer)))
972 '(anything-compile-source--candidates-in-buffer
973 anything-compile-source--match-plugin
))))
974 (expect '(("SourceName cib search-from-end" ("bar" "foo")))
975 (let ((anything-mp-match-source-name t
))
976 (anything-test-candidates '(((name .
"SourceName cib search-from-end")
979 (with-current-buffer (anything-candidate-buffer 'global
)
980 (insert "foo\nbar\n"))))
982 (candidates-in-buffer)))
984 '(anything-compile-source--candidates-in-buffer
985 anything-compile-source--match-plugin
))))
987 ;; (anything-compile-sources '(((name . "test"))) anything-compile-source-functions)
988 (provide 'anything-match-plugin
)
990 ;; How to save (DO NOT REMOVE!!)
991 ;; (progn (magit-push) (emacswiki-post "anything-match-plugin.el"))
992 ;;; anything-match-plugin.el ends here