[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/inf-ruby 4962bb076e 141/265: inf-ruby-console-patterns-ali
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/inf-ruby 4962bb076e 141/265: inf-ruby-console-patterns-alist: Accept predicate function in cars |
Date: |
Sat, 9 Jul 2022 21:59:20 -0400 (EDT) |
branch: elpa/inf-ruby
commit 4962bb076edb5aa855c9c8a74832b4e9a485fcd8
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
inf-ruby-console-patterns-alist: Accept predicate function in cars
Use it to detect Rails better, #67
---
inf-ruby.el | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/inf-ruby.el b/inf-ruby.el
index 31f777dc99..139f93299e 100755
--- a/inf-ruby.el
+++ b/inf-ruby.el
@@ -587,20 +587,24 @@ keymaps to bind `inf-ruby-switch-from-compilation' to
`ะก-x C-q'."
'inf-ruby-switch-from-compilation)))
(defvar inf-ruby-console-patterns-alist
- '(("bin/rails" . rails)
+ '((inf-ruby-console-rails-p . rails)
("*.gemspec" . gem)
+ (inf-ruby-console-racksh-p . racksh)
("Gemfile" . default))
- "Mapping from file name patterns to name symbols.
+ "Mapping from predicates (wildcard patterns or functions) to name symbols.
`inf-ruby-console-auto' walks up from the current directory until
-one of the patterns matches, then calls `inf-ruby-console-NAME',
+one of the predicates matches, then calls `inf-ruby-console-NAME',
passing it the found directory.")
(defun inf-ruby-console-match (dir)
"Find matching console command for DIR, if any."
(catch 'type
(dolist (pair inf-ruby-console-patterns-alist)
- (let ((default-directory dir))
- (when (file-expand-wildcards (car pair))
+ (let ((default-directory dir)
+ (pred (car pair)))
+ (when (if (stringp pred)
+ (file-expand-wildcards pred)
+ (funcall pred))
(throw 'type (cdr pair)))))))
;;;###autoload
@@ -616,6 +620,10 @@ automatically."
(unless type (error "No matching directory found"))
(funcall fun dir)))
+(defun inf-ruby-console-rails-p ()
+ (and (file-exists-p "Gemfile.lock")
+ (inf-ruby-file-contents-match "Gemfile.lock" "^ +railties ")))
+
;;;###autoload
(defun inf-ruby-console-rails (dir)
"Run Rails console in DIR."
@@ -672,9 +680,19 @@ Gemfile, it should use the `gemspec' instruction."
""))))
(run-ruby (concat base-command args) "gem")))
+(defun inf-ruby-console-racksh-p ()
+ (and (file-exists-p "Gemfile.lock")
+ (inf-ruby-file-contents-match "Gemfile.lock" "^ +racksh ")))
+
+(defun inf-ruby-console-racksh (dir)
+ "Run racksh in DIR."
+ (interactive "D")
+ (let ((default-directory (file-name-as-directory dir)))
+ (run-ruby "bundle exec racksh" "racksh")))
+
;;;###autoload
(defun inf-ruby-console-default (dir)
- "Run racksh, custom console.rb, or just IRB, in DIR."
+ "Run custom console.rb, Pry, or bundle console, in DIR."
(interactive "D")
(let ((default-directory (file-name-as-directory dir)))
(unless (file-exists-p "Gemfile")
@@ -682,8 +700,6 @@ Gemfile, it should use the `gemspec' instruction."
(cond
((file-exists-p "console.rb")
(run-ruby "bundle exec ruby console.rb" "console.rb"))
- ((inf-ruby-file-contents-match "Gemfile" "[\"']racksh[\"']")
- (run-ruby "bundle exec racksh" "racksh"))
((inf-ruby-file-contents-match "Gemfile" "[\"']pry[\"']")
(run-ruby "bundle exec pry" "pry"))
(t
- [nongnu] elpa/inf-ruby 6c85470ce4 110/265: inf-ruby-implementations: use '--noreadline', (continued)
- [nongnu] elpa/inf-ruby 6c85470ce4 110/265: inf-ruby-implementations: use '--noreadline', ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 524a86c90b 089/265: Set PAGER locally unless it's set, fixes #33, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 2d65630b7d 100/265: Introduce `ruby-switch-to-last-ruby-buffer', ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 2cb21b9f58 090/265: Make PAGER override unconditional, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 23929579a6 124/265: Merge pull request #57 from bbatsov/compilation-warnings, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby e4cf0593da 116/265: inf-ruby-console-gem: require the main file if it exists, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 27acc75257 113/265: inf-ruby-console-rails: prompt for the environment, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 0697315485 109/265: Merge pull request #52 from abicky/support-dir-without-traiing-slash, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 451aa1d858 145/265: Merge pull request #71 from jasonko/master, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 46917f463c 151/265: Integrate with projectile-rails-server-mode, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 4962bb076e 141/265: inf-ruby-console-patterns-alist: Accept predicate function in cars,
ELPA Syncer <=
- [nongnu] elpa/inf-ruby c59d7d0a23 134/265: inf-ruby-console-default: Prioritize console.rb if it exists, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby e91b349e4f 168/265: Hook up inf-ruby-auto-exit inside inf-ruby-auto-enter, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 106972ded1 165/265: Touch up docstrings and rename MODE-VAR to MODE, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 0ed06255ec 179/265: Allow running multiple ruby processes, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 536a68528c 184/265: Make ruby-last-ruby-buffer buffer-local, ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby d1e6e9e669 003/265: Bugfix: Escape the completion seed., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby ed768ce413 004/265: Evaluate code sent via 'ruby-send-region' in the same binding as the REPL., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 68a7ad32fa 006/265: Bugfix: Don't stall Emacs when there is no valid completion output., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby 06e2b1e29e 008/265: Bugfix: Complete only when point is at a top-level prompt., ELPA Syncer, 2022/07/09
- [nongnu] elpa/inf-ruby ec0d30ad19 019/265: Merge pull request #5 from lewang/quote_fix, ELPA Syncer, 2022/07/09