Google-like search info for Emacs - search

Is there a package/function to search info pages from emacs similarly to web search? I mean you just give few words, and the emacs returns you all the pages with these words. The words can be in any order, maybe use fuzzy match etc., regexp does not help a lot in this case. The similar question is discussed in http://www.emacswiki.org/emacs/SearchNear but I'm not satisfied with the solution. Does anybody know more general software?
Ideally, such kind of search should handle not only info pages, but any source, for example all open buffers.

I think that you may be looking for info-apropos which you can call with M-x info-apropos. This performs a full-text search of the info files and returns a hyperlink list of sections containing the word.
I don't think that it does multiple words like a search engine, but it may get you started.

Anything.el has a configuration for searching Info pages. It's called anything-c-info-pages and looks like it searches for info topics, so it's not exactly what you want, but if you know elisp then you can copy this source and easily modify it to perform full text search instead.
If you don't know Anything then here's an introduction and an other one about creating your own sources for it.

For a more powerful and flexible alternative see Emacs Anything. To fetch it do
git clone git://repo.or.cz/anything-config.git ~/anything-config
in your terminal. Then add the following code snippet to your Emacs configuration file ~/.emacs:
(byte-recompile-directory "~/anything-config")
(add-to-list 'load-path "~/anything-config" t)
(load "~/anything-config/anything.elc")
(load "~/anything-config/anything-config.elc")
Finally run it using M-x anything.
I prefer to bind it to Alt-X by adding the following line to ~/.emacs.:
(global-set-key (kbd "M-X") 'anything)

Related

Failing to search multiple buffers in Emacs using "icicle-search-buffer" and C-RET

I am trying to use the icicle-search-file/icicle-search-buffer commands, but am having the same problem with both where C-RET seems to perform no operation on completion options once I have already entered the search context pattern.
The operations described are using Emacs 24.3.1 on Ubuntu 13.10 with icicles, workgroups2, and some custom key bindings all done with H-_ or C-c _ to avoid conflicts. I have icicles and workgroups2 set to be on at start in my .emacs file. I don’t have anything custom bound to C-c `.
I have learned to use icicle-search (C-c `) with progressive completion (S-SPC) and it works well, which is why I wanted to figure out these commands.
I have called the icicle-search-buffer command with each of these options just to be sure there is no difference, and the result are the same:
C-9 C-c `
M-s M-s b
M-x icicle-search-buffer RET
I enter the search regex (.* RET - to make things simple) just as with icicle-search, and am then prompted for the buffers to search. I move through the completion options with arrow keys and use C-RET on the buffers I want to search. The result of this is the buffer I chose disappearing from the completion list and no obvious result appearing. Hitting RET at any point just searches the buffer I had active before beginning the search, just as if I had used C-c `. It does not search the currently selected buffer in the completions list.
Does anyone see where I am failing to understand the usage of these commands? I have read through the information on the Icicles - Search Commands, Overview page.
The "Search Multiple Buffers, Files, and Bookmarks" section seems to describe this simply, but beyond using C-RET not much is said that suggests to me where my problem is.
I also followed the link in that section to the Icicles - Multi-Commands page
which was helpful in seeing how icicles modifies vanilla Emacs commands and how multi-commands work in general, but I could not determine from that where my mistake is.
You were doing nothing wrong. (And your description of using Icicles search is a good one.)
I introduced a bug recently.
Should be OK now. Please download the latest version of icicles-mac.el. Or wait (up to a day) for it to be mirrored on MELPA and download it from there. Sorry for your trouble, and thanks for bringing this to my attention.
IMPORTANT:
If you byte-compile Icicles (recommended), then whenever (as now) icicles-mac.el is updated, you
must load icicles-mac.el (not just icicles-mac.elc), then compile it, then *recompile ALL***of the other **Icicles source files as well. You want to make sure that all byte-compiled files are up-to-date.
This is normal for Lisp. Code that depends on macros needs to be byte-compiled anew after loading the updated macros.

Generally, how do I "go to definition" in VIM? Then how do I with golang?

Two part question:
First, when using VIM what process do I take and what keys do I type to "go to definition" or "go to declaration" etc.? This document might be the answer to my question, but I can't get it to work, so I'm unsure. It looks like its merely text matching the string rather than finding the true definition. If I can get this to work, then will I be able to jump outside of the current document to a definition/declaration? Or does this only work within a single document?
Second, how do I make this work specifically with the Go programming language? It sure would be nice to "click" the Client in
clnt := &http.Client{Transport: tr}
And be taken to the actual code that defines an http.Client.
Possible? How?
As you guess, gd (and other commands) is merely text matching, vim doesn't understand the syntax as it is just a text editor, :h gd will explain how gd works.
Usually, 'go to definition' is brought by using CTRL-] and tag files. A user manual about this topic can be read by :h 29.1.
First you need to generate a tags file for your project, as latest Exuberant Ctags has supported golang (from here), command
cd /path/to/your/project
ctags -f tags -R --fields=+K+a
will do the job.
Second, open vim, by default vim will find tag files under working directory (according to 'tags' option), if the tag file is found successfully, then CTRL-]` should works well.
Also check two useful plugins Tagbar and Easytags.
For golang, you can use the application godef to do it. The pluging vim-go helps you on setting everything, so, you just type 'gd' in a definition and it goes to the exact definition.
https://github.com/fatih/vim-go/blob/master/doc/vim-go.txt

Code navigation in vim and emacs

The IDE feature that I miss the most in emacs and vim are code navigation and find usages. Both of these editor have the following similar features for them:
Tags - identifiers from specified files are indexed and when you press shortcut on a word which is an identifier, you will be navigated there
CScope - it allows you to navigate to "usages" of an identifier
As far as I understand, both of these systems are very imprecise. If we have similar identifiers with the same name both tags and scope might mix them up. Are there any better alternatives and how precise they really are?
I use cscope and semantic in Emacs. It is just enough for me.
In cscope the two function I heavily used are cscope-find-global-definition and cscope-find-this-symbol. The previous function is quite precise.
C-c s s Find symbol.
C-c s d Find global definition.
As for semantic(dynamic index, do not need to generate TAGS).
(global-set-key [f8] 'semantic-ia-fast-jump) ;; jump to definition.
(global-set-key [S-f8] ;; jump back
(lambda ()
(interactive)
(if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
(error "Semantic Bookmark ring is currently empty"))
(let* ((ring (oref semantic-mru-bookmark-ring ring))
(alist (semantic-mrub-ring-to-assoc-list ring))
(first (cdr (car alist))))
(if (semantic-equivalent-tag-p (oref first tag)
(semantic-current-tag))
(setq first (cdr (car (cdr alist)))))
(semantic-mrub-switch-tags first))))
GNU Global, for example, allows duplicate identifiers, and you'll be able to select needed.
There are many programs that output ctags-compatible tags files. They are often language-specific because of some low level limitations in ctags but neither they nor ctags help you when you have multiple methods with the same name because these tools only do the indexing part of the job. Searching through the index is actually Vim's job and, because it is a freaking text editor and not an IDE it has zero mean to decide which method declaration is the right one.
Fortunately, Vim shows an actionable list when there are multiple hits. But that's how far you can go.
Cscope is a little smarter than ctags and, when used from Vim, does the searching as well as the indexing. But, like ctags, cscope is still a code indexer.
It's actually possible to use both at the same time with set cscopetags but it won't help with your naming issue.
You could try GNU Global. But it doesn't support JavaScript so I've never really used it long enough to make an opinion.
IDEs usually do their magic through language-specific parsers/static analysis tools that run in the background against your code. Vim has at least one limitation and one feature that make it hard to even imagine it ever reaching the level of code awareness that you seem to be looking for:
Vim is not multithreaded. So it can't run a static analysis tool in the background.
Vim supports hundreds of languages. Providing that kind of feature for that many languages would be impossible for any organization of any size.
But none of this is a problem for me, because Vim is not an IDE.
And because I don't have multiple methods with the same name in my projects.
<C-]>, <C-w>}, :tag /foo<Tab> and :cs f c bar are enough for my humble needs.
See eclim which has a very usable emacs interface which supports the same level of code navigation for java as Eclipse.
Eclim also supoprts C/C++ among others, though support for this is not yet implemented in emacs-eclim, but if you know Elisp then it is pretty trivial to implement, because for java all the necessary infrastructure is already there, so you only need to add the implementation for the c++ calls.

Search tags only in current file

I am using ":ta " to jump to a method.
For example i got two classes named A.java and B.java. They both have a foo() method and B.java have another method called fooBar(). Then i open A.java and input :ta foo then press TAB then i will got two completion : foo and fooBar. But what i want to jump now is just tag in current file, i don't like tag in other file to display.
And i found tagslist does very good in this job. So if i can use the tag generated by taglist to search from, it will be very nice.
Depending on how many times you call your methods a couple of * may be enough.
Without using tags, gd can be used to go to the local declaration of the method under your cursor. I tend to choose the most low-tech solution usually, so I would go with this one.
But ctags is also able to generate tags for a single file only or for an arbitrary selection of files. It can be done in a few steps but it's definetely not as straightforward as what you are accustomed to do…
Create a file with the name(s) of the file(s) you want to scan. Let's say it's called files.txt and it's located at the root of your working directory.
Generate your tags file using the -L <file> argument: ctags -L files.txt.
At this point you should have a tags file containing only the tags present in the file(s) specified at step 1.
Generating different tags files for the whole project and for single files may be useful, here. A short script generating a tags file named after the current file and making it the sole tags source may make the whole thing easier.
EDIT
Actually, TagList and TagBar don't generate tags files. The output of the ctags <options> command they run is used internally and parsed with all kinds of regexp to filter by scope or filename or whatever.
Unfortunately this cannot be done using ctags. Ctags does not respect context, it is a pure list of all possible "functions". Try to open a tag file with an editor (e.g. vim) and you will see it is just a list of "functions" (in case of Java they are "methods"). Example:
getDesc src/com/redhat/rhn/internal/doclet/Handler.java /^ public String getDesc() {$/;" m class:Handler
getDoc src/com/redhat/rhn/internal/doclet/ApiCall.java /^ public String getDoc() {$/;" m class:ApiCall
Vim just search the file "as is" without giving it any context - it just search for a "function". It is able to search for files, classes, methods, enums etc. Tags format is described in more detail here: http://ctags.sourceforge.net/FORMAT
In Vim you have few possibilities. There are several plugins that gives Vim some context sensitivity, but you cannot use tags for that. Vim itself has a feature called OmniComplete and there are few plugins dedicated for Java. Then you can use Ctrl-X Ctrl-O to start a completition. I recommend you to map this to a different key (maybe Ctrl-Space if you like). More info about Java OmniComplete plugins here:
Vim omnicompletion for Java
Eclim (http://eclim.org/) is very comperhensive, but difficult to setup (you need to run Eclipse in the background). JDE script is easier and also robust (http://www.vim.org/scripts/script.php?script_id=1213). And please note IntelliJ IDEA Community Edition (free) also has a very nice Vim plugin that is free to use. But I understand you - Vim is Vim.
Good luck!
Not exactly an answer to your question, but it seems like there's no way to do exactly what you need, so, i would recommend you the following: for your Java development in Vim, try eclim.
This tool helps you to use your favorite text editor Vim with power of an Eclipse (IDE).
I can't find analogue for tab-completion of :ta, but i know a smart analogue for g] : this is a command :JavaSearchContext. You can map it to something.
For example, if you have two classes A and B, and you have method foo() in each class, then g] will ask you every time you want to jump to foo(), but :JavaSearchContext will always jump to the proper declaration of foo().
Of course, there are many other features.

Which editors out of Emacs, Vim and JEdit support multiple simultaneous text insertion points?

Background: JEdit (and some other text editors as well) support a feature called Multiple simultaneous text insertion points. (at least that's what I'm calling it here).
To understand what this means, take a look at the link.
Out of all the features in use in modern text editors, initial research seems to indicate that this is one feature that both Emacs and Vim do not actually support. If correct, this would be pretty exceptional since it's quite difficult to find a text editor feature that has not made its way into at least one of these two old-school editors.
Question: Has anyone ever seen or implemented this feature in either Emacs, Vim, or both? If so, please point me to a link, script, reference or summary that explains the details.
If you know an alternate way to do the same (or similar) thing, please let me know.
The vim way to do this is the . command which repeats the last change. So, for instance, if I change a pointer to a reference and I have a bunch of
obj->func
that I want to change to
obj.func
then I search for obj->, do 2cw to change the obj-> to obj., then do n.n.n. until all the instances are changed.
Perhaps not a flexible as what you're talking about, but it works frequently and is very intuitive and fast when it does.
moccur-edit.el almost does what you want. All the locations matching the regexp are displayed, and the editing the matches makes changes in the corresponding source. However, the editing is done on a single instance of the occurrence.
I imagine it'd be straight forward to extend it to allow you to edit them all simultaneously (at least in the simple case).
There is a demo of it found here.
Turns out, the newest versions of moccur-edit don't apply changes in real-time - you must apply the changes. The changes are also now undoable (nice win).
In EMACS, you could/would do it with M-x find-grep and a macro. If you really insist that it be fully automatic, then you'd include the find-next in the macro.
But honestly, this strikes me as a sort of Microsoft-feature: yes, it adds to the feature list, but why bother? And would you remember it existed in six months, when you want to use it again?
For emacs, multiple-cursors does exactly that.
Have a look at emacsrocks episode 13, by the author of the module.
I don't think this feature has a direct analogue in either Emacs or Vim, which is not to say that everything achievable with this feature is not possible in some fashion with the two 'old-school' editors. And like most things Emacs and Vim, power-users would probably be able to achieve such a task exceedingly quickly, even if mere mortals like myself could spend five minutes figuring out the correct grep search and replace with appropriate back-references, for example.
YASnippet package for Emacs uses it. See 2:13 and 2:44 in the screencast.
Another slight similarity: In Emacs, the rectangle editing features provided by cua-selection-mode (or cua-mode) automatically gives you multiple insertion points down the left or right edge of the marked rectangle, so that you can type a common prefix or suffix to all of those lines.
e.g.:
M-x cua-selection-mode RET (enable the global minor mode, if you don't already use this or cua-mode)
C-RET down down down (marks a 1x3 character rectangle)
type prefix here
C-RET (unmark the rectangle to return to normal editing)
It should be something like this in vim:
%s/paint.\((.*),/\1.paint(/
Or something like that, I am really bad at "mock" regular expressions.
The idea is substitute the pattern:
/paint(object,/
with
/object.paint(/
So, yes, it is "supported"
It seemed simple to do a basic version of this in Emacs lisp. This is for when you just want two places to insert text in parallel:
(defun cjw-multi-insert (text)
"insert text at both point and mark"
(interactive "sText:")
(insert-before-markers text)
(save-excursion
(exchange-point-and-mark)
(insert-before-markers text)))
When you run it, it prompts for text and inserts it at both point (current position) and mark. You can set the mark with C-SPC. This could be easily extended for N different positions. A function like set-insert-point would record current position (stored as an Emacs marker) into a list and then when you run the multi-insert command, it just iterates through the list adding text at each.
I'm not sure about what would a simple way to handle a more general "multi-editing" feature.
Nope. This would be quite difficult to do with a primarily console-based UI.
That said, there is similar features in vim (and emacs, although I've not used it nearly as much) - search and replace, as people have said, and more similarly, column insert mode: http://pivotallabs.com/users/brian/blog/articles/350-column-edit-mode-in-vi

Resources