Skip to content
Browse files

* helm-tags.el (helm-c-etags-select): wrap thing-at-point in regexp.

  • Loading branch information...
1 parent c235e76 commit 1a5f5e6024272bab8cc9c004dceeb63a25ef5258 @thierryvolpiatto thierryvolpiatto committed Dec 22, 2012
Showing with 1 addition and 0 deletions.
  1. +1 −0 helm-tags.el
View
1 helm-tags.el
@@ -245,6 +245,7 @@ If tag file have been modified reinitialize cache."
(if (and tag (file-exists-p tag))
(helm :sources 'helm-c-source-etags-select
:keymap helm-c-etags-map
+ :default (concat "\\_<" (thing-at-point 'symbol) "\\_>")
:buffer "*helm etags*")
(message "Error: No tag file found, please create one with etags shell command."))))

4 comments on commit 1a5f5e6

@dgutov
dgutov commented on 1a5f5e6 Dec 22, 2012

This is a fine change, but it can lead to false negatives when the current syntax table has set some characters' syntax to symbol when they're not in the default syntax table. For example, with Ruby, last time I checked, it failed to find methods like include? and compact!.

My solution was (haven't used etags for some time now) to set the candidates' buffer syntax table to the current buffer's one:
https://github.com/dgutov/dot-emacs/blob/master/bow.el#L84

That, in turn, may make things a little weirder when the tags file has indexed files written in different languages, but I think it's less of a problem.

@thierryvolpiatto
emacs-helm member
@dgutov
dgutov commented on 1a5f5e6 Dec 24, 2012

Have you tried without your config? seems you are using "\<" (regexp-quote symbol) "\>", try with just symbol.

Indeed, without quoting, with Ruby you don't get false negatives, you get false positives instead, because ? is a special character in regexps. It would be different if ! did actually belong to the symbol syntax class (it doesn't, not entirely sure why), but here's the example with question marks: https://gist.github.com/4370325 (the tags file may need to be re-generated).

Open b.rb, put the cursor on broken!, press M-x helm-c-etags-select, you'll see 3 candidates. Same thing if you start with broke!.
Put the cursor on broken?, you'll see all 6 methods as candidates, which is definitely bad.

With the syntax table changed, and with quoting, it would be 2, 2, and just 1 candidate respectively.

It is not a good solution because you can run helm etags on other directories (projects) unrelated with the current major-mode of your buffer.

It's not perfect, but it has an upside (see above), and I don't think it makes anything really worse. After all, there shouldn't be a pre-existing assumption about what syntax table the candidates buffer uses. I'm still not sure, for example, if it's text-mode-syntax-table or the default one, and what characters exactly belong to the symbol syntax in either of them.

M-x helm-find-files => navigate => M-.

AFAICT, the default value is an empty string in this scenario, so the syntax table will only be used if the user types some special regexp character themselves.

@thierryvolpiatto
emacs-helm member
Please sign in to comment.
Something went wrong with that request. Please try again.