summaryrefslogtreecommitdiff
path: root/lisp/progmodes/ruby-mode.el
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2019-05-30 19:41:16 +0300
committerDmitry Gutov <dgutov@yandex.ru>2019-05-30 20:09:53 +0300
commit27f5627104a073762c3b1d21e55822ec2d2e0347 (patch)
tree667447465669629be53cda5bd8b94c9cfbb8b9a3 /lisp/progmodes/ruby-mode.el
parentb367a3dee13d46fc44a49d4a94d5142e1f98c6da (diff)
downloademacs-27f5627104a073762c3b1d21e55822ec2d2e0347.tar.gz
New command ruby-find-library-file
* lisp/progmodes/ruby-mode.el (ruby-find-library-file): New command. (ruby-mode-map): Add binding for it.
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r--lisp/progmodes/ruby-mode.el23
1 files changed, 23 insertions, 0 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 4fceda89373..80e809b9d63 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -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:]]\\)"