helpful

a fork of Wilfred's helpful
git clone https://git.trogloxene.org/helpful.git
Log | Files | Refs | README

commit 28bae3e2bd64c6b89c1607c7b1235b306fa7220b
parent 309dba6bb8b199c4ae0f6202f76cd7fa2d42081c
Author: Nick Drozd <nicholasdrozd@gmail.com>
Date:   Sat, 16 Feb 2019 15:01:37 -0600

Handle C-style names in helpful-symbol

In Emacs's C core, Lisp functions and variables take on slightly
different names: dashes are replaced with underscores, and functions
and variables are prefixed with "F" and "V" respectively. This change
allows for looking up those symbols. For example, if I am looking at
the source for `purecopy':

  DEFUN ("purecopy", Fpurecopy, Spurecopy, 1, 1, 0,
         doc: /* Make a copy of object OBJ in pure storage.
  Recursively copies contents of vectors and cons cells.
  Does not copy symbols.  Copies strings without text properties.  */)
    (register Lisp_Object obj)
  {
    if (NILP (Vpurify_flag))
      return obj;
    else if (MARKERP (obj) || OVERLAYP (obj) || SYMBOLP (obj))
      /* Can't purify those.  */
      return obj;
    else
      return purecopy (obj);
  }

I can run `helpful-at-point' on `Vpurify_flag'.

This doesn't support running C-style names through `helpful-callable'
etc, but that doesn't seem like a useful feature.

Diffstat:
MCHANGELOG.md | 2++
Mhelpful.el | 22++++++++++++++++++++++
Mtest/helpful-unit-test.el | 14++++++++++++++
3 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -14,6 +14,8 @@ macros. Fixed issues with functions that had more than one advice active. +Added looking up C-style Lisp names. + # v0.15 Fixed a crash on formatting values. diff --git a/helpful.el b/helpful.el @@ -2392,6 +2392,20 @@ or :foo." (or (fboundp symbol) (helpful--variable-p symbol))) +(defun helpful--convert-c-name (symbol var) + "Convert SYMBOL from a C name to an Elisp name. +E.g. convert `Fmake_string' to `make-string' or +`Vgc_cons_percentage' to `gc-cons-percentage'. Interpret +SYMBOL as variable name if VAR, else a function name. Return +nil if SYMBOL doesn't begin with \"F\" or \"V\"." + (let ((string (symbol-name symbol)) + (prefix (if var "V" "F"))) + (when (s-starts-with-p prefix string) + (intern + (s-chop-prefix + prefix + (s-replace "_" "-" string)))))) + ;;;###autoload (defun helpful-symbol (symbol) "Show help for SYMBOL, a variable, function or macro. @@ -2410,6 +2424,14 @@ See also `helpful-callable' and `helpful-variable'." (helpful-callable symbol)) ((boundp symbol) (helpful-variable symbol)) + ((let ((fsym (helpful--convert-c-name symbol nil))) + (when (fboundp fsym) + (helpful-callable fsym) + fsym))) + ((let ((vsym (helpful--convert-c-name symbol t))) + (when (boundp vsym) + (helpful-variable vsym) + vsym))) (t (user-error "Not bound: %S" symbol)))) diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el @@ -866,3 +866,17 @@ find the source code." (helpful-variable 'inhibit-read-only) (should (s-contains-p "Value\nnil" (buffer-string)))) + +(ert-deftest helpful--convert-c-name () + (should + (equal + 'make-string + (helpful--convert-c-name 'Fmake_string nil))) + (should + (equal + 'gc-cons-percentage + (helpful--convert-c-name 'Vgc_cons_percentage t))) + (should-not + (helpful--convert-c-name 'Fmake_string t)) + (should-not + (helpful--convert-c-name 'Vgc_cons_percentage nil)))