aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2019-05-30 19:41:16 +0300
committerDmitry Gutov2019-05-30 20:09:53 +0300
commit27f5627104a073762c3b1d21e55822ec2d2e0347 (patch)
tree667447465669629be53cda5bd8b94c9cfbb8b9a3
parentb367a3dee13d46fc44a49d4a94d5142e1f98c6da (diff)
downloademacs-27f5627104a073762c3b1d21e55822ec2d2e0347.tar.gz
emacs-27f5627104a073762c3b1d21e55822ec2d2e0347.zip
New command ruby-find-library-file
* lisp/progmodes/ruby-mode.el (ruby-find-library-file): New command. (ruby-mode-map): Add binding for it.
-rw-r--r--etc/NEWS2
-rw-r--r--lisp/progmodes/ruby-mode.el23
2 files changed, 25 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index a2306c06f69..5cce76f8df0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -733,6 +733,8 @@ it can't find the config file.
733 733
734*** Rubocop is called with 'bundle exec' if Gemfile mentions it. 734*** Rubocop is called with 'bundle exec' if Gemfile mentions it.
735 735
736*** New command 'ruby-find-library-file' bound to 'C-c C-f'.
737
736** Package 738** Package
737 739
738*** Change of 'package-check-signature' for packages with multiple sigs 740*** Change of 'package-check-signature' for packages with multiple sigs
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'."
155 (define-key map (kbd "M-C-n") 'ruby-end-of-block) 155 (define-key map (kbd "M-C-n") 'ruby-end-of-block)
156 (define-key map (kbd "C-c {") 'ruby-toggle-block) 156 (define-key map (kbd "C-c {") 'ruby-toggle-block)
157 (define-key map (kbd "C-c '") 'ruby-toggle-string-quotes) 157 (define-key map (kbd "C-c '") 'ruby-toggle-string-quotes)
158 (define-key map (kbd "C-c C-f") 'ruby-find-library-file)
158 map) 159 map)
159 "Keymap used in Ruby mode.") 160 "Keymap used in Ruby mode.")
160 161
@@ -1802,6 +1803,28 @@ If the result is do-end block, it will always be multiline."
1802 (format "%s%s%s" string-quote content string-quote)) 1803 (format "%s%s%s" string-quote content string-quote))
1803 (goto-char orig-point))))) 1804 (goto-char orig-point)))))
1804 1805
1806(defun ruby-find-library-file (&optional feature-name)
1807 "Visit a library file denoted by FEATURE-NAME.
1808FEATURE-NAME is a relative file name, file extension is optional.
1809This commands delegates to 'gem which', which searches both
1810installed gems and the standard library. When called
1811interactively, defaults to the feature name in the 'require'
1812statement around point."
1813 (interactive)
1814 (unless feature-name
1815 (let ((init (save-excursion
1816 (forward-line 0)
1817 (when (looking-at "require [\"']\\(.?*\\)[\"']")
1818 (match-string 1)))))
1819 (setq feature-name (read-string "Feature name: " init))))
1820 (let ((out
1821 (substring
1822 (shell-command-to-string (concat "gem which " feature-name))
1823 0 -1)))
1824 (if (string-match-p "\\`ERROR" out)
1825 (user-error "%s" out)
1826 (find-file out))))
1827
1805(eval-and-compile 1828(eval-and-compile
1806 (defconst ruby-percent-literal-beg-re 1829 (defconst ruby-percent-literal-beg-re
1807 "\\(%\\)[qQrswWxIi]?\\([[:punct:]]\\)" 1830 "\\(%\\)[qQrswWxIi]?\\([[:punct:]]\\)"