]> git.eshelyaron.com Git - emacs.git/commitdiff
New command ruby-find-library-file
authorDmitry Gutov <dgutov@yandex.ru>
Thu, 30 May 2019 16:41:16 +0000 (19:41 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Thu, 30 May 2019 17:09:53 +0000 (20:09 +0300)
* lisp/progmodes/ruby-mode.el (ruby-find-library-file):
New command.
(ruby-mode-map): Add binding for it.

etc/NEWS
lisp/progmodes/ruby-mode.el

index a2306c06f69df81aa664cef36cd74ec58b980df4..5cce76f8df08f866fec4f6e70ff8c1d7fcd64a28 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -733,6 +733,8 @@ it can't find the config file.
 
 *** Rubocop is called with 'bundle exec' if Gemfile mentions it.
 
+*** New command 'ruby-find-library-file' bound to 'C-c C-f'.
+
 ** Package
 
 *** Change of 'package-check-signature' for packages with multiple sigs
index 4fceda8937385653d3002c0951e790751027f4a2..80e809b9d639e7db95010a548a1df53b50ef1459 100644 (file)
@@ -155,6 +155,7 @@ This should only be called after matching against `ruby-here-doc-beg-re'."
     (define-key map (kbd "M-C-n") 'ruby-end-of-block)
     (define-key map (kbd "C-c {") 'ruby-toggle-block)
     (define-key map (kbd "C-c '") 'ruby-toggle-string-quotes)
+    (define-key map (kbd "C-c C-f") 'ruby-find-library-file)
     map)
   "Keymap used in Ruby mode.")
 
@@ -1802,6 +1803,28 @@ If the result is do-end block, it will always be multiline."
          (format "%s%s%s" string-quote content string-quote))
         (goto-char orig-point)))))
 
+(defun ruby-find-library-file (&optional feature-name)
+  "Visit a library file denoted by FEATURE-NAME.
+FEATURE-NAME is a relative file name, file extension is optional.
+This commands delegates to 'gem which', which searches both
+installed gems and the standard library.  When called
+interactively, defaults to the feature name in the 'require'
+statement around point."
+  (interactive)
+  (unless feature-name
+    (let ((init (save-excursion
+                  (forward-line 0)
+                  (when (looking-at "require [\"']\\(.?*\\)[\"']")
+                    (match-string 1)))))
+      (setq feature-name (read-string "Feature name: " init))))
+  (let ((out
+         (substring
+          (shell-command-to-string (concat "gem which " feature-name))
+          0 -1)))
+    (if (string-match-p "\\`ERROR" out)
+        (user-error "%s" out)
+      (find-file out))))
+
 (eval-and-compile
   (defconst ruby-percent-literal-beg-re
     "\\(%\\)[qQrswWxIi]?\\([[:punct:]]\\)"