1 ;;;; anything-multi-sources.el --- concatenate candidates in multi souces
3 ;; Copyright (C) 2010 rubikitch
5 ;; Author: rubikitch <rubikitch@ruby-lang.org>
6 ;; Keywords: anything, experimental
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/anything-multi-sources.el
9 ;; This file is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This file is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
30 ;; Below are complete command list:
33 ;;; Customizable Options:
35 ;; Below are customizable option list:
41 ;; All of the above can customize by:
42 ;; M-x customize-group RET anything-multi-sources RET
47 (eval-when-compile (require 'cl
))
48 (defgroup anything-multi-sources nil
49 "anything-multi-sources"
52 (defvar anything-multi-source-delimiter-candidates
53 '("anything-multi-source-delimiter-candidates--3e3r3x903oj09fnreiojioxe"))
54 (defvar anything-multi-source-delimiter-name
55 "anything-multi-source-delimiter-name--339024u3fz09e90390ir309330923")
56 (defvar anything-multi-source-delimiter
57 `((name .
,anything-multi-source-delimiter-name
)
58 (init . anything-multi-source-delimiter-init
)
62 (candidates . anything-multi-source-delimiter-candidates
)))
64 (defun anything-multi-source-delimiter-init ()
65 (setq anything-source-in-each-line-flag t
))
67 (defun ams-delete-delimiter-source ()
68 (delete-region (point) (progn (forward-line 3) (point))))
69 (defun anything-multi-sources-update-function ()
74 (push (buffer-substring-no-properties (point-at-bol) (point-at-eol))
78 (some (lambda (source)
79 (if (equal (assoc-default 'name source
)
80 (buffer-substring (point-at-bol) (point-at-eol)))
82 (anything-get-sources))))
83 (rewrite-first-source-name
85 (overlay-put (make-overlay (line-beginning-position)
87 'display
(mapconcat 'identity
89 (reverse (cdr concat-headers
))
91 in-multi-source delimiter-flag concat-header-pos concat-headers
92 multi-source-start multi-source-end
)
94 (progn (forward-line 1)
95 (setq pos
(anything-get-next-header-pos))))
100 (equal (car concat-headers
) anything-multi-source-delimiter-name
))
101 (when (and (not delimiter-flag
) ;delete header
103 (delete-region (1- (point)) (progn (forward-line 1) (point))))
105 (cond ((not in-multi-source
)
106 (setq concat-header-pos
(point))
107 (setq concat-headers nil
)
109 (forward-line 1) ; anything-get-next-header-pos workaround
111 (goto-char (anything-get-next-header-pos))
112 (funcall push-line
)))
114 (ams-delete-delimiter-source)
115 (if (equal (buffer-substring-no-properties (point-at-bol) (point-at-eol))
116 anything-multi-source-delimiter-name
)
117 (ams-delete-delimiter-source)
118 (save-excursion (forward-line 1) (setq multi-source-start
(point)))
119 (setq in-multi-source
(not in-multi-source
))))
122 (forward-line -
1) (setq multi-source-end
(point))
123 (goto-char (1- multi-source-start
))
125 multi-source-start multi-source-end
(funcall first-source
)))
126 (ams-delete-delimiter-source)
128 (goto-char concat-header-pos
)
129 (funcall rewrite-first-source-name
))
130 (setq in-multi-source
(not in-multi-source
))))))))
132 (defun ams-sort-candidates (s e source
)
133 (sort-numeric-fields 1 s e
))
135 (add-hook 'anything-update-hook
'anything-multi-sources-update-function
)
136 (provide 'anything-multi-sources
)
138 ;; How to save (DO NOT REMOVE!!)
139 ;; (emacswiki-post "anything-multi-sources.el")
140 ;;; anything-multi-sources.el ends here