AnythingProposals

Proposals for anything.el

Sticky help ?

Hello rubikitch!

It might be easy implementable (or already implemented?) but I could not figure it out. I use anything for many things but the most used is the documentation look-up. Would it be possible, while in anything buffer to show a help string in the pop-up buffer? I would prefer to have it sticky, i.e. the help is always that of the highlighted candidate. An invocation by the key is also fine, but it should not dismiss the anything buffer.

Thanks, RedBlue.

Got it; persistent-action feature is great! I added persistent actions to anything-c-source-emacs-functions and anything-c-source-emacs-variables. Now C-z displays help on candidate:
  (defvar anything-c-source-emacs-functions
  '((name . "Emacs Functions")
    (candidates . (lambda ()
                    (let (commands)
                      (mapatoms (lambda (a) (if (functionp a)
                                                (push (symbol-name a) commands))))
                      (sort commands 'string-lessp))))
    (type . function)
    (persistent-action . describe-function )
    (persistent-help . "Show function's help.")
    (requires-pattern . 2))
  "Source for completing Emacs functions.")

  (defvar anything-c-source-emacs-variables
  '((name . "Emacs Variables")
    (candidates . (lambda ()
                    (sort (all-completions "" obarray 'boundp) 'string-lessp)))
    (type . variable)
    (persistent-action . describe-variable)
    (persistent-help . "Show variable's help.")
    (requires-pattern . 2))
  "Source for completing Emacs variables.")

And the sticky action could be implemented by rebinding the default keys with :keymap argument. But now, I am not so sure that I want it:)

Thanks for the package, RedBlue.

subject-predicate-attributes paradigm

Just a random thought for a possible future improvement in anything.el: the current implementation could be extended, so that it supports the Quicksilver-like subject-predicate-attributes paradigm:

The user first chooses the subject of the command (an application, a file, an e-mail address, an IM contact, a bookmark, etc.), then an action (predicate) to be performed on that subject, and finally additional details (attributes) for the action.

This would add further versatility for actions which can have an additional parameter. For example, when moving a file to a folder the user chooses the file (subject), chooses the Move To action (predicate) and then chooses a folder where the file is moved (attribute).

Of course, it involves heavy changes in the current code, so it’s only food for thought for times when the maintainer needs ideas how to improve Anything further. :)

There may be more practical applications than the file moving example above. One can look up the plugins for Quicksilver or Gnome Do for further ispiration.

TamasPatrovics

Isn’t this already doable, with anything commands as actions ?

Lisp:anything.el itself does not have ‘details’ feature. But some action functions in Lisp:anything-config.el asks details. Details are included in actions in Anything. For example, ‘M-x anything-regexp’, ‘M-x anything-w3m-bookmarks’, ‘M-x anything-bbdb’, and so on. – rubikitch

Fuzzy completion

see for example: http://mirrors.wikifusion.info/gnu/elisp-archive/packages/fuzzy-match.el.Z

It should be a proposal for anything-config, since the match attribute is provided by the platform, so the default match algorithm can be overriden with it. So someone should provide a match function which anything-config would optionally offer for sources – TamasPatrovics

Request: Quick start / tutorial

Hi, ‘anything’ looks fantastic but I’m not sure how to get started. It would be really helpful to me if someone could put together a short introduction/tutorial for setting up anything.el.

Something like “download anything.el and anything-config.el, add something to your .emacs, create a file for personal options and run <command> in emacs…” is all I need. I’m just not sure how I’m supposed to set this thing up.

Thanks!

– sneazle

I’m writing anything-startup.el to address installation/configuration complexity. The file will have useful configuration and many anything applications with user-friendly comments. It aims to be a template. – rubikitch

Great - I added a very basic Getting Started section at the top now, because I figured some of it out. Would you be so kind as to update the Getting Started section once it’s ready?

Visible marks functions

A few extra functions for visible marks:

(defun anything-unmark-all (arg)
  "With no prefix arg (or if ARG is nil when called from a function), unmark all candidates.
With a single prefix arg (or a value of 4 for ARG), unmark all visible candidates.
With a double prefix arg (or a value of 16 for ARG), unmark all non-visible candidates."
  (interactive "p")
  (with-anything-window 
    (save-excursion
      (cond ((eq arg 1) ; unmark all candidates
             (setq anything-visible-mark-overlays nil)
             (setq anything-c-marked-candidate-list nil)
             (setq anything-marked-candidates nil))
            ((> arg 3) ; unmark all visible/non-visible candidates
             (goto-char (point-min))
             (anything-next-line)
             (if (not (anything-this-visible-mark))
                 (anything-next-visible-mark))
             (let* ((pnts (remove nil (mapcar 'overlay-start anything-visible-mark-overlays)))
                    (maxpoint (if pnts (eval `(max ,@pnts)) 0))
                    temp-overlays temp-candidates temp-c-candidates)
               (while (<= (point) maxpoint)
                 (anything-aif (anything-this-visible-mark)
                     (if (eq arg 4) ; unmark visible candidates if single prefix
                         (anything-delete-visible-mark it)
                       ;; else add to temp vars to replace marked candidates
                       ;; (thus unmarking non-visible candidates)
                       (progn (add-to-list 'temp-overlays it)
                              (add-to-list 'temp-candidates
                                           (cons (anything-get-current-source)
                                                 (anything-get-selection)))
                              (add-to-list 'temp-c-candidates
                                           (anything-current-line-contents)))))
                 (if (< (point) maxpoint) (anything-next-visible-mark)
                   (setq maxpoint (1- maxpoint))))))))
    (anything-mark-current-line))
  (if (< arg 5)
      (anything-force-update)))

    
(defun anything-mark-all ()
  "Mark all unmarked candidates.
NOTE: this will not affect candidates that are not visible. To do that you need to
redisplay all candidates first (e.g. by pressing C-k)."
  (interactive)
  (with-anything-window
    (save-excursion
      (goto-char (point-min))
      (anything-next-line)
      (let ((maxline (1- (line-number-at-pos (point-max)))))
        (while (< (current-line) maxline)
          (if (not (anything-this-visible-mark))
              (anything-make-visible-mark))
            (anything-next-line))
        (if (not (anything-this-visible-mark))
            (anything-make-visible-mark))))
    (anything-mark-current-line)))

(defun anything-toggle-all-marks ()
  "Toggle marks of all visible candidates.
NOTE: this will not affect candidates that are not visible. To do that you need to
redisplay all candidates first (e.g. by pressing C-k)."
  (interactive)
  (with-anything-window
    (save-excursion
      (goto-char (point-min))
      (anything-next-line)
      (let ((maxline (1- (line-number-at-pos (point-max)))))
        (while (< (current-line) maxline)
          (anything-toggle-visible-mark))
        (anything-toggle-visible-mark)))
    (anything-mark-current-line)))

(defun anything-kill-marked-candidates ()
  "Store each marked visible candidate to the kill-ring (as seperate items),
or if no visible candidates are marked, store the current candidate.
This function does not quit anything when it has finished.
NOTE: this will not affect candidates that are not visible. To do that you need to
redisplay all candidates first (e.g. by pressing C-k)."
  (interactive)
  (with-anything-window
    (save-excursion
      (let ((max (length (anything-marked-candidates)))
            (count 0))
        (if (eq max 1)
            (kill-new (anything-get-selection nil t))
          (goto-char (point-min))
          (while (< count max)
            (anything-next-visible-mark)
            (kill-new (anything-get-selection nil t))
            (setq count (1+ count))))))
    (anything-mark-current-line)))

    
(define-key anything-map (kbd "M-k") 'anything-kill-marked-candidates)
(define-key anything-map (kbd "M-u") 'anything-unmark-all)
(define-key anything-map (kbd "M-m") 'anything-mark-all)
(define-key anything-map (kbd "M-t") 'anything-toggle-all-marks)

JoeBloggs

Incidentally rubikitch, what is the point of visible marks on actions? Do you intend to implement a feature to apply all marked actions? (cannot think of any specific examples of when this would be useful, but it feels like it should be).

These functions are not acceptable since the display in anything is not always the same like it is in dired for example. With anything-find-files for example, the display change at each time you change directory and the marks you put here will not be visible there.

ThierryVolpiatto

I have changed ‘anything-unmark-all’ so that you can choose whether to unmark all, all visible, or all non-visible marked candidates. I think the behaviour for ‘anything-toggle-all-marks’, ‘anything-mark-all’ and ‘anything-kill-marked-candidates’ is OK since in these cases you probably only want to affect the visible candidates, and you can always redisplay all candidates (by deleting minibuffer contents) if you need to affect all candidates. What do you think?

JoeBloggs

You should always unmark all, no need to unmark only visibles or non--visibles. If you have more than one source, your code will mark all candidates of all sources, you should act only on current source. BTW i have created a new google group at https://groups.google.com/group/emacs-anything?hl=en where it’s easier to communicate that here.

ThierryVolpiatto


Proposals for anything-config.el

You can post your anything-c-source-* in AnythingSources.

Similar to Imenu: fume aka functions-menu integration

I don’t know it. It seems not to come with emacs and I cannot find anything about it here on the wiki. Please provide a patch. --TassiloHorn

Dired Jump

Anything can make life inside Emacs easier in a million ways! How can we share ideas on how to use it? Here’s one I’m trying these days:

(setq my-dired-places '(( "project1" "c:/home/project1/")
			( "project2" "c:/home/project2/")))

(defun special-dired-jump (name)
  (dired-other-window (cadr (assoc name my-dired-places))))

(defvar anything-dired-commonplace
  `((name . "Dired common places")
	(candidates . (lambda () (mapcar (lambda (x) (nth 0 x)) my-dired-places)))
    (action . (("Dired jump" . special-dired-jump)))))

What’s wrong with bookmarks? Lisp:anything-config.el defines a ‘Bookmarks’ source (see above). Your ‘my-dired-places’ seems to be just another set of bookmarks that can only be directories. Or am I missing something? – DrewAdams

I think I know what he’s getting at. Usually I work with files from several directories, so I open up a dired for each of them. I’d like to have an anything source be a list of files gleaned from every dired buffer. -Sunil Patel

Implemented in anything-config.el! Use ‘anything-c-source-files-in-all-dired’. – rubikitch

Awesome!! Thanks :) . – sunilpatel

Org-Agenda-Headlines

As far as I can see, anything-c-source-org-headline only works on one file. Orgmode users usually define a set of files they are currently very much interested in: The Agenda files, saved in org-agenda-files. These files are the core org files to this user. Would it be possible to extend the functionality of org-headline to work on all files in org-agenda-files? – Memnon Anon

Sorry, no. The headline plug-in intends to extract headlines in current file. But, replacing org-agenda interface with anything is interesting idea. Code is welcome. – rubikitch

Okay. I keep all my bookmarks (www,info,lines in files etc.) in an orgfile, and it would be neat to gain access to them quickly via anything. Might take a while, but I will figure out how I can make anything-c-source-org-headline loop over the files in org-agenda-files and return the results: Time to learn some elisp ;). – Memnon Anon

Create the candidates function that splits an orgfile into entries. Then create an action that extracts the link from an entry. ‘org-map-entries’ would help you. – rubikitch

Anything Sources Selection

Slight improvement to ‘anything-c-source-call-source’ function: replace ‘candidate’ with `(anything-marked-candidates)’ in call to ‘anything’ function in ‘action’ attribute. Then you can select multiple sources by marking them first with ‘C-SPC’.

JoeBloggs

Other Anything-related proposals

toggle anything-match-plugin on/off

I find the anything-match-plugin to be too slow for filtering large sources (e.g emacs variables/functions/commands). This is even when I have `(setq anything-mp-highlight-delay nil)’. It would be nice if it was possible to toggle between match plugin filtering and normal filtering.

JoeBloggs

Check out last version on git and M-x anything-c-toggle-match-plugin.

ThierryVolpiatto

Thanks! – JoeBloggs

Hmm, now I get the following problem: Symbol’s function definition is void: anything-compile-source--match-plugin

JoeBloggs

This is not helpful send me a recipe of what you are doing (you can send by mail), it seem you have not required match-plugin, in this case of course you can’t toggle it.

ThierryVolpiatto

Ahh.. yes.. (blushes), I forgot that I’d commented out the require statement.

I have another request though; the value of ‘anything-mp-highlight-delay’ is not preserved if you turn the match-plugin off and then on again. If I set it to nil, then apply ‘anything-c-toggle-match-plugin’ twice (perhaps with some intervening commands) it is set back to 0.7. Could this be fixed?

JoeBloggs

Yes, i have hardcoded the original value (0.7) i will fix that as soon as possible.

ThierryVolpiatto

Mailing list

An emacs-anything mailing list would be great.

anything-etag improvement

It would be nice if the file name were shown with the matching tag. eg in rails if I search on `show` it brings up a bunch of matches but no way of knowing which controller they are in. Something like what the standard tags-apropos displays would be nice. So I have patched the existing anything-etags.el to show the filename each match belongs to it is here https://github.com/wolfmanjm/anything-on-rails/raw/master/vendor/anything-etags.el Feel free to incorporate it into the existing version, or maybe it should be yet another version? – WolfmanJM

Implemented Proposals for anything-config.el

Highlighting matches

(defvar anything-match-face 'bold)

(defun anything-insert-match (match insert-function)
  "Insert MATCH into the anything buffer. If MATCH is a list then
insert the string inteneded to appear on the display and store
the real value in a text property."
  (let ((beg (line-beginning-position))
        (end (line-end-position))
        (string (if (listp match) (car match) match)))
    (funcall insert-function string)

    (if (listp match)
        (put-text-property beg end
                           'anything-realvalue (cdr match)))
    (if (and anything-match-face
             (string-match anything-pattern string))
        (put-text-property (+ beg (match-beginning 0))
                           (+ end (match-end 0))
                           'face anything-match-face))

    (funcall insert-function "\n")))

Matsuyama

imenu on emacs23

This source have add in Lisp:anything-config.elAndyStewart

Here are the sources i use on

GNU Emacs 23.0.60.1 (i686-pc-linux-gnu, GTK+ Version 2.12.11) of 2008-09-03 on tux

for imenu

That define three sections in anything:

  • imenu types
  • imenu variables
  • imenu functions

NOTE: if you use icicles and imenu+.el it will not work

why? ⇒ i don’t know :)

However, ‘icicle-anything’ work very well with this code.

The output is better than with the normal icicle-imenu.

(defvar anything-c-imenu-cache-types nil)
(make-variable-buffer-local 'anything-c-imenu-cache-types)
(defvar anything-c-source-imenu-types
  '((name . "Imenu Types")
    (init . (lambda ()
              (require 'imenu)
              (setq anything-c-imenu-current-buffer
                    (current-buffer))
              (condition-case nil
                  (setq anything-c-imenu-cache-types
                        (assoc "Types" (imenu--make-index-alist)))
                (error nil))))
    (candidates . (lambda ()
                    (condition-case nil
                        (with-current-buffer anything-c-imenu-current-buffer
                          (mapcar (lambda (x)
                                    ;; Don't append cdr to history
                                    ;; it will corrupt file
                                    (car x))
                                  (remove-if-not (lambda (x)
                                                   (when (listp x)
                                                     (markerp (cdr x))))
                                                 anything-c-imenu-cache-types)))
                      (error nil))))
    (volatile)
    (action
     ("Imenu Types" . (lambda (item)
                            (anything-c-imenu item anything-c-imenu-cache-types))))))


(defvar anything-c-imenu-cache-var nil)
(make-variable-buffer-local 'anything-c-imenu-cache-var)
(defvar anything-c-source-imenu-variables
  '((name . "Imenu Variables")
    (init . (lambda ()
              (require 'imenu)
              (setq anything-c-imenu-current-buffer
                    (current-buffer))
              (condition-case nil
                  (setq anything-c-imenu-cache-var
                        (assoc "Variables" (imenu--make-index-alist)))
                (error nil))))
    (candidates . (lambda ()
                    (condition-case nil
                        (with-current-buffer anything-c-imenu-current-buffer
                          (mapcar (lambda (x)
                                    ;; Don't append cdr to history
                                    ;; it will corrupt file
                                    (car x))
                                  (remove-if-not (lambda (x)
                                                   (when (listp x)
                                                     (markerp (cdr x))))
                                                 anything-c-imenu-cache-var)))
                      (error nil))))
    (volatile)
    (action
     ("Imenu Variables" . (lambda (item)
                            (anything-c-imenu item anything-c-imenu-cache-var)))
     ("Describe variable" . (lambda (item)
                              (describe-variable (intern item))))
     ("Add variable to kill ring" . kill-new))))

(defvar anything-c-imenu-cache-func nil)
(make-variable-buffer-local 'anything-c-imenu-cache-func)
(defvar anything-c-source-imenu-functions
  '((name . "Imenu Functions")
    (init . (lambda ()
              (require 'imenu)
              (setq anything-c-imenu-current-buffer
                    (current-buffer))
              (condition-case nil
                  (setq anything-c-imenu-cache-func
                        (cddr (imenu--make-index-alist)))
                (error nil))))

    (candidates . (lambda ()
                    (condition-case nil
                        (with-current-buffer anything-c-imenu-current-buffer
                          (mapcar (lambda (x)
                                    ;; Don't append cdr to history
                                    ;; it will corrupt file
                                    (car x))
                                  (remove-if-not (lambda (x)
                                                   (when (listp x)
                                                     (markerp (cdr x))))
                                                 anything-c-imenu-cache-func)))
                      (error nil))))
    (volatile)
    (action
     ("Imenu Functions" . (lambda (item)
                            (anything-c-imenu item anything-c-imenu-cache-func)))
     ("Describe function" . (lambda (item)
                              (describe-function (intern item))))
     ("Add function to kill ring" . kill-new))
    (candidate-transformer . (lambda (candidates)
                               (anything-c-compose
                                (list candidates)
                                '(anything-c-mark-interactive-functions))))))

(defun anything-c-imenu (item cache)
  (imenu
   (assoc item cache))
  (highlight-regexp item)
  (sit-for 1)
  (unhighlight-regexp item))

ThierryVolpiatto


bookmarks sorted

This source have add in Lisp:anything-config.elAndyStewart

Thats the same source-bookmarks but sorted like Emacs bookmarks

Tested on:

GNU Emacs 23.0.60.1 (i686-pc-linux-gnu, GTK+ Version 2.12.11) of 2008-09-03 on tux

(defvar anything-c-source-bookmarks
  '((name . "Bookmarks")
    (init . (lambda ()
              (require 'bookmark)))
    (candidates . (lambda ()
                    (let (lis)
                      (setq lis (bookmark-all-names))
                      (sort lis 'string-lessp))))
    ;(volatile)
    (type . bookmark))
  "See (info \"(emacs)Bookmarks\").")

Jabber contacts

This source have add in Lisp:anything-config.elAndyStewart

For those who use JabberEl:

(defun anything-c-jabber-online-contacts ()
  "List online Jabber contacts."
  (let (jids)
    (dolist (item (jabber-concat-rosters) jids)
      (when (get item 'connected)        
        (push (if (get item 'name)
                  (cons (get item 'name) item)
                (cons (symbol-name item) item)) jids)))))

(defvar anything-c-source-jabber-contacts
  '((name . "Jabber Contacts")
    (init . (lambda () (require 'jabber)))
    (candidates . (lambda ()
                    (mapcar
                     'car
                     (anything-c-jabber-online-contacts))))
    (action . (lambda (x)
                (jabber-chat-with
                 (jabber-read-account)
                 (symbol-name
                  (cdr (assoc x (anything-c-jabber-online-contacts)))))))))

Added! Thanks Mathias. --TassiloHorn


Shortening home path

I think tilde(~) is more readable than $HOME. Don’t you?

(defun anything-c-shorten-home-path (files)
-  "Replaces /home/user with $HOME."
+  "Replaces /home/user with ~."
  (mapcar (lambda (file)
            ;; 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)
+                  (cons (replace-match "~" nil nil file) file)
                file)))
          files))

Yes! – rubikitch


Anything