emacsorphanage / helm-gtags

GNU GLOBAL helm interface
203 stars 31 forks source link

Add helm-gtags-symbol-at-point-function to support generic types #187

Closed pascalhaakmat closed 4 years ago

pascalhaakmat commented 5 years ago

helm-gtags uses (thing-at-point 'symbol) to get a symbol in some places.

However (thing-at-point 'symbol) does not work well with generic types, such as List<TypeA>.

It would be useful if the function which is used to find a symbol could be customized to support better support of generics or other types of syntax that are not handled by (thing-at-point 'symbol).

This pull request adds a helm-gtags-symbol-at-point-function to support this. This allows for example:

(defun ph-find-symbol-at-point ()
  "Find symbol at point.

If the symbol matches a generic type in
C++/C#/Kotlin/Java (e.g. List<TypeA<TypeB>>), then the function
returns the word at point."
  (let ((token (thing-at-point 'symbol 'no-text-props)))
    (if (string-match "\\([^<>]+\\)<\\(.+\\)>" token)
        (thing-at-point 'word 'no-text-props)
      token)))

(setq helm-gtags-symbol-at-point-function 'ph-find-symbol-at-point)
sergeyklay commented 4 years ago

@jcs090218 @syohex What with this PR? Could you please take a look.

jcs090218 commented 4 years ago

Merged! Sounds reasonable! :) Thanks for the contribution!