]> code.delx.au - gnu-emacs-elpa/commitdiff
Handle symbol-at-point better in non-Elisp buffers
authorOleh Krehel <ohwoeowho@gmail.com>
Tue, 2 Jun 2015 06:48:38 +0000 (08:48 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Tue, 2 Jun 2015 06:48:38 +0000 (08:48 +0200)
* counsel.el (counsel-symbol-at-point): New defun.
(counsel-describe-variable): Update.
(counsel-describe-function): Update.

Fixes #126

counsel.el

index f27095e6d1a6f925f06de27c55a9b08878452470..6be445f081dcf13fc4f384047af37367f2a9784f 100644 (file)
 (defvar counsel-describe-symbol-history nil
   "History for `counsel-describe-variable' and `counsel-describe-function'.")
 
+(defun counsel-symbol-at-point ()
+  "Return current symbol at point as a string."
+  (let ((s (thing-at-point 'symbol)))
+    (and (stringp s)
+         (if (string-match "\\'\\(.*\\)'\\'" s)
+             (match-string 1 s)
+           s))))
+
 (defun counsel-describe-variable ()
   "Forward to `describe-variable'."
   (interactive)
             (push (symbol-name vv) cands))))
        cands)
      :keymap counsel-describe-map
-     :preselect (thing-at-point 'symbol)
+     :preselect (counsel-symbol-at-point)
      :history 'counsel-describe-symbol-history
      :require-match t
      :sort t
                      (push (symbol-name x) cands))))
                 cands)
               :keymap counsel-describe-map
-              :preselect (thing-at-point 'symbol)
+              :preselect (counsel-symbol-at-point)
               :history 'counsel-describe-symbol-history
               :require-match t
               :sort t