Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better `counsel-semantics`? #702

Closed
xuhdev opened this issue Oct 6, 2016 · 9 comments

Comments

@xuhdev
Copy link
Contributor

commented Oct 6, 2016

helm-semantics seems displaying nicer list of different types of symbols: jorgenschaefer/elpy#866 (comment)

Is it possible to improve counsel-semantics like that?

@abo-abo

This comment has been minimized.

Copy link
Owner

commented Oct 6, 2016

A better counsel-semantic is available:

  • in lispy for LISP dialects
  • in lpy for Python
  • in function-args for C/C++

@xuhdev xuhdev closed this Nov 1, 2016

@xuhdev xuhdev reopened this Nov 1, 2016

@Yevgnen

This comment has been minimized.

Copy link
Contributor

commented Dec 28, 2016

Here is a dirty solution. You can still remove the helm-semantic dependency by copying one or two more helm functions. Since I'm still using helm, I don't mind no matter how dirty it is. 😂

;; Counsel semantic
(defvar counsel-semantic--tags-cache nil)
(defun counsel-semantic ()
  (interactive)
  (require 'helm-semantic)
  (when (semantic-parse-tree-needs-update-p)
    (semantic-parse-tree-set-needs-update))
  (setq counsel-semantic--tags-cache (semantic-fetch-tags))
  (ivy-read "Semantic tags: "
            (with-temp-buffer
              (helm-semantic--fetch-candidates counsel-semantic--tags-cache 0)
              (split-string (buffer-substring (point-min) (point-max)) "\n" t))
            :preselect (thing-at-point 'symbol)
            :require-match t
            :action (lambda (candidate)
                      (let* ((pos (if (string-prefix-p " " candidate)
                                      (next-single-property-change 0 'semantic-tag candidate (length candidate))
                                    0))
                             (tag (get-text-property pos 'semantic-tag candidate)))
                        (semantic-go-to-tag tag)))
            :caller 'counsel-semantic))

(defun counsel-semantic-or-imenu ()
  (interactive)
  (if (semantic-active-p)
      (call-interactively #'counsel-semantic)
    (call-interactively #'counsel-imenu)))

screen shot 2016-12-28 at 4 34 27 pm

@abo-abo

This comment has been minimized.

Copy link
Owner

commented Dec 29, 2016

@Yevgnen That's a pretty good solution. It's nice to reuse the candidate list of helm-semantic, too bad it's not cleanly returned by a single function.

@eflanigan00

This comment has been minimized.

Copy link

commented Dec 14, 2017

Any update on this? I'd love to remove helm-semantic-or-imenu from my keybindings 💯

@Yevgnen

This comment has been minimized.

Copy link
Contributor

commented Dec 14, 2017

No from me... I'm still using my mixed version of counsel-semantic...

  ;; Counsel semantic
  (defvar counsel-semantic--tags-cache nil)
  (defun counsel-semantic ()
    (interactive)
    (require 'helm-semantic)
    (when (semantic-parse-tree-needs-update-p)
      (semantic-parse-tree-set-needs-update))
    (setq counsel-semantic--tags-cache (semantic-fetch-tags))
    (ivy-read "Semantic tags: "
              (with-temp-buffer
                (helm-semantic--fetch-candidates counsel-semantic--tags-cache 0)
                (split-string (buffer-substring (point-min) (point-max)) "\n" t))
              :preselect (thing-at-point 'symbol)
              :require-match t
              :action (lambda (candidate)
                        (let* ((pos (if (string-prefix-p " " candidate)
                                        (next-single-property-change 0 'semantic-tag candidate (length candidate))
                                      0))
                               (tag (get-text-property pos 'semantic-tag candidate)))
                          (semantic-go-to-tag tag)))
              :caller 'counsel-semantic)
    (run-hooks 'imenu-after-jump-hook))

  (defun counsel-semantic-or-imenu ()
    (interactive)
    (if (semantic-active-p)
        (call-interactively #'counsel-semantic)
      (call-interactively #'counsel-imenu)))

@abo-abo abo-abo closed this in 6f9b319 Dec 30, 2017

@abo-abo

This comment has been minimized.

Copy link
Owner

commented Dec 30, 2017

@xuhdev Thanks, please test.
@Yevgnen Thanks for the pointer.
@eflanigan00 Thanks for the donation.

@eflanigan00

This comment has been minimized.

Copy link

commented Dec 30, 2017

@abo-abo
I don't see any class variables or methods like in xuhdev's original link. I notice that counsel-imenu shows them.

Can you also add the counsel-semantic-or-imenu from Yevgnen?
Thanks for the great work!

@abo-abo

This comment has been minimized.

Copy link
Owner

commented Dec 31, 2017

I don't see any class variables or methods

Nice catch, fixed.

Can you also add the counsel-semantic-or-imenu from Yevgnen?

Added.

Thanks for the great work!

You're welcome.

@xuhdev

This comment has been minimized.

Copy link
Contributor Author

commented Jan 5, 2018

It works well. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.