When I enter "pars" in Emacs js-mode buffer and type tern-ac-complete, I get the desired result: list of completion candidates + the documentation next to the candidate.
However, I cannot get Tern completion to be triggered automatically. The ac-auto-start is set to 3 and the auto-complete works as expected for other cases (my dictionary file, the words I already typed in, jquery-doc, etc.)
You should try company-mode with the third-party company-tern.
It starts completion automatically with no problems.
The issue is that tern does not provide an ac-source yet. From the comments in tern-auto-complete.el
This program does not provide an ac-source for arbitrary timing yet.
Call function 'edebug-defun for function 'ac-start of auto-complete.el,
and follow call trace to figure out what causes this problem.
In my case, variable 'ac-use-dictionary-as-stop-words was t and having many words on my auto completion dictionary,
so auto-complete was aborted.
tern.el : Version: 0.0.1
auto-complete.el : Version: 1.4.0
line. 1559 (ac-abort)) ;; <= This was called!!!
$ node --version # v0.11.13-pre (on Linux)
This happens because tern-emacs has to request completions from tern-server (an async operation). Only when the server returns it goes on to call auto-complete with the tern sources only.
I fixed it by advising auto-complete to wait for tern request if a custom variable is set to t. This way you can get tern completions to show in your normal auto-complete workflow.
Here is the pull request (or just the diff) I made to the tern repo.
I'm adding this here in case someone stumbles here through search as i did.
Related
I use company-mode a lot on natural language completion with the local dictionary. I am wondering if there is a way to automatically add a whitespace upon completion.
For example, currently when I type abili and select the first candidate ability, my insert point is right after y|. Is there a way that the company-mode can add a space so my insert point is after y |?
I could not find any related information on this but this issue mentioned a space is added after completion in the Eshell mode. Apparently this is exactly what I want.
The issue mentioned the function completion-at-point. Is there a way that I can change or have a function that I can override the current completion mechanism?
Thanks! I’d really appreciate any suggestions.
You could add a hook to company-after-completion-hook that would be called after completion with any of your company backends, eg.
(defun my-company-after-completion-hook (&rest _ignored)
;; this would be called with the completion candidate, so you could
;; modify it to insert spaces based on the candidate
(just-one-space))
;; or setq-local in a mode hook, eg. for text-mode/org-mode or wherever you are
;; completing with dictionary words
(setq company-after-completion-hook #'my-company-after-completion-hook)
If you only wanted to add space after completing with a specific backend you could see if the backend already implements a post-completion action, otherwise you could probably advise it.
I'm trying to use icicle-command-abbrev to reduce the amount of typing that I do. I have proxy candidates enabled (setq icicle-add-proxy-candidates-flag t), (I can also enable them with C-M-_ but, for some reason, I can never get ff to match find-file. Sorting is set to proxy coandidates first, and I have proxy candidates with a higher precedence than regular commands. What am I doing wrong?
You don't really say what behavior you see, corresponding to "I can never get ff to match find-file." Let me tell you what behavior you should see, and then you can please tell me what the difference is.
From your description, you should see proxy candidates in *Completions*. When you use icicle-command-abbrev (bound to C-x SPC by default) and then you type ff TAB at the M-x prompt, you should see command names that have at least two parts that start with f, and you should see the proxy candidate ff, which should be highlighted (with face icicle-proxy-candidate). That proxy candidate should be the first candidate listed in *Completions* (because you have sorted proxy candidates first).
If you then cycle to that candidate (just hit TAB a second time, or the down arrow once), and then hit RET to choose it, the prompt should change to Command abbreviatedff:. If you then hit TAB you should see in *Completions* the list of commands whose names have at least two parts that start with f. You can then cycle to one or type more text to complete to one, to choose it.
Let me know which part of this description you do not see.
However, I just realized that there was a bug (a missing variable binding), which I have now fixed. The symptom would be that when you choose command find-file a missing-variable-binding error was raised. Please download the latest icicles-cmd1.el, which has the fix. (Or wait until the file is mirrored on MELPA, which could take up to a day.)
If what you see other than that bug is what I described, then you should be OK with the new version. If not, please describe what you see that is different from my description. Sorry for your trouble.
(You can of course just hit RET as soon as you type ff, to get the second completion prompt directly. But first check that the recipe above works for you.)
I am using emacs and the auto-newline feature is not working as expected. I have a pretty large number of customizations done to my emacs. So it would be no wonder if one of the other customizations is not what auto-line is expecting. I would like to know if there is a way to know the list of commands (list of emacs commands) executed by emacs at a particular point, for e.g. when ctrl-s ctrl-c or in my case when auto-line feature is called.
edit : I think you have misunderstood the question. I would like to know what command emacs calls 'internally'.
I believe view-lossage is what you're looking for -- M-x view-lossage, or C-h l.
If you want to know what a keystroke is bound to, consider using describe-key, which is usually bound to C-h k.
Basically at this point, you need to bite the bullet and learn some Emacs-lisp. The debugger is what you are looking for to dig further into your problem (I use edebug). It's not just about seeing what functions get called, you also need to see the values of the relevant variables when those functions are called.
If you feel you're not up to it, then you can bi-sect your init file until you find the culprit, but at that point you still need some Emacs-lisp to investigate further.
To add to what #event_jr said --
What you seem to be asking is the history of the functions called by the command you last invoked. (You speak of Emacs "internal commands", but it seems you just mean functions.)
To get that history for any given command you invoke (e.g., by a key), use M-x debug-on-entry and then enter the command name. The next time you use that command, you can walk through its execution in the Emacs debugger (hit d to step, c to continue past a step).
I have a HTML page, with html-mode enabled. I call function sgml-validate to check for any markup errors. It's based on compilation-mode. I want to remove some warnings from the compilation output, so I wrote a function and hooked it to compilation-filter-hook (this variable is not documented, but compilation-filter invokes it). Everything works. My problem is that how can I ensure my filter function only gets called when I started the compilation process on a HTML page (via sgml-validate)?
I see two methods, but none of them worked:
First, I can check the value of major-mode. But it always returns compilation-mode, since that is enabled on the *compilation* buffer. (I found a filter function in the source code of grep+, and they did check the value of major-mode. I can't figure out how can it work correctly.)
The other idea was than to only hook my filter function to the HTML file's buffer, but for similar reasons it couldn't work as the output of compilation process goes to a seperate buffer.
It sounds like you can advise smgl-validate so that it performs the filtering before it performs all it's other operations. For example:
(defadvice sgml-validate (around fix-filtering command activate)
(let ((return-value ad-do-it))
(filter-function return-value))))
Meanwhile, I found that compilation-start accepts an optional argument mode, which will be the major mode for the compilation buffer. So I can create a major mode derived from compilation-mode, and define there my filter function now hooked to the proper buffer.
The only problem is now that sgml-validate does not allow me to set the mode argument on compilation-start, but that's another question.
(I don't consider this the ultimate solution, of course.)
Surprisingly as you get good at vim, you can code even faster than standard IDEs such as Eclipse. But one thing I really miss is code completion, especially for long variable names and functions.
Is there any way to enable code completion for Perl in vim?
Ctrl-P (Get Previous Match) and Ctrl-N (Get Next Match) are kind of pseudo code completion. They basically search the file (Backwards for Ctrl-P, Forwards for Ctrl-N) you are editing (and any open buffers, and if you are using TAGS anything in your TAG file) for words that start with what you are typing and add a drop down list. It works surprisingly well for variables and function names, even if it isn't intellisense. Generally I use Ctrl-P as the variable or function I am looking for is usually behind in the code. Also if you keep the same copy of Vim open, it will search the files you have previously opened.
Vim 7 supports omni completion.
For example, I have this in my vimrc
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
and then, when I press Ctrl-X Ctrl-O in Insert mode, I get a dropdown list of autocomplete possibilities.
Here's an omnicfunc for perl. No idea how well it works though.
Well, Vim's generic completion mechanism is surprisingly good, just using Ctrl-N in insert mode. Also, line completion is very handy, using C-x C-l.
Also check out this vim script for perl.
The standard Ctrl+N and Ctrl+P works even better if you add the following to your ~/.vim/ftplugin/perl.vim file:
set iskeyword+=:
Then it will autocomplete module names, etc.
The .vimrc clip in one of the other answers is slightly wrong. To turn your tab key into an auto-complete key, use this code:
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
You can find this, and tons of other vim tricks in this thread at Perlmonks--which links to even more threads with lots more customizations.
You should look at the SuperTab plugin:
http://www.vim.org/scripts/script.php?script_id=1643
It let's you do completion (either the OmniCompletion or the regular completion) using tab and shift-tab instead of ^N and ^P.
https://github.com/c9s/perlomni.vim
Ctrl+N
This is explained in the Perl Hacks book, along with how to do Package completion. Highly recommended.