[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs interface to Recoll other than Helm?
From: |
Angel de Vicente |
Subject: |
Re: Emacs interface to Recoll other than Helm? |
Date: |
Wed, 08 Nov 2017 12:40:37 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) |
Hi,
Angel de Vicente <angelv@iac.es> writes:
> What I would like is something more like what you get in the Recoll GUI
> (or, for example, when you do a multi-occur search), where you get a
> buffer with the files matching, together with some context and an easy
> way to open a particular file at the point where the match was
> found. Something like:
> http://picpaste.com/counsel-recoll-mo-uQUXHGey.png
OK, so I rolled up my sleeves and made a hack that works just fine
(though for the moment it is very crude and most options are
hard-coded).
In case somebody else wants to try, I just defined the following
function in my .emacs (I have ivy/swiper/counsel, ag and recoll
installed):
,----
| (defun ag-recoll (string directory)
| "Search using ag based on the findings of recoll. Search will be done in a
given DIRECTORY,
| and the STRING will be interpreted as concatenated by ANDs for recoll and
with ORs for ag.
|
| The idea is that when I search, for example, for 'openacc mpi', recoll
will give me all the
| files that have those two words somewhere in the file, and ag will find
lines that match
| any of the terms.
|
| For the moment this is very crude, and most options to recoll and ag are
hard-coded in the
| ag-recoll.sh script, most notably that ag will look for a maximum of 10
matches in each file
| to avoid huge lists with common searches."
|
| (interactive (list (ag/read-from-minibuffer "Search string")
| (read-directory-name "Directory: ")))
| (setq command-string (format "%s %s %s"
"/home/angelv/localhacks/ag-recoll.sh" directory string))
| (setq regexp nil)
| (compilation-start
| command-string
| #'ag-mode
| `(lambda (mode-name) ,(ag/buffer-name string directory regexp))))
`----
which uses the ag-recoll.sh script:
,----
| #!/bin/bash
| dir=$1; shift
| ors=$(printf '%s|' ${@})
| recoll -t -b $@ dir:$dir | sed -e "s/file:\/\///" | xargs -d '\n' ag
--max-count 10 --group --line-number --column --color --color-match 30\;43
--color-path 1\;32 --smart-case ${ors%|}
`----
So, as an example, when I call ag-recoll with STRING 'openacc pgi' and
DIRECTORY /home/angelv/Learning, the result is like this:
http://picpaste.com/pics/ag-recoll-CdCrnsru.1510144253.png
where each line is a hyperlink to the corresponding match in the file,
you can use the common grep-mode commands to open a file, go to the next
match C-x `, etc.
I will be using this from now on, and if I find it useful I will try to
make it more flexible (being able to pass arguments to recoll and ag,
etc. [I'm a total noob with Emacs Lisp, so any suggestions on how to
improve the code are very welcome].
Cheers,
--
Ángel de Vicente
http://angel-de-vicente.blogspot.com/
Re: Emacs interface to Recoll other than Helm?, Joost Kremers, 2017/11/07