[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e3e1f51 052/272: ivy.el (ivy-ffap-url-functions): Customiz
From: |
Oleh Krehel |
Subject: |
[elpa] master e3e1f51 052/272: ivy.el (ivy-ffap-url-functions): Customize "C-x C-f M-n" |
Date: |
Mon, 25 Apr 2016 10:13:16 +0000 |
branch: master
commit e3e1f51eecbe78d06528d06e35fae3ea0459eb3d
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el (ivy-ffap-url-functions): Customize "C-x C-f M-n"
* ivy.el (ivy-ffap-url-functions): New defvar.
(ivy--cd-maybe): When calling a function in `ivy-ffap-url-functions'
results in a string, stop completion and open that string with
`ffap-url-fetcher'.
* counsel.el (counsel-github-url-p): New defun.
(ivy-ffap-url-functions): Add `counsel-github-url-p' to the list.
This feature allows to quickly visit Github issues from either
`magit-commit-mode' or from a version-controlled file. The point has to
be at the "#" char in e.g. "#123", that represents an issue.
It's possible to customize `ivy-ffap-url-functions' to do a similar
thing for places other than Github.
The "C-x C-f M-n" key binding will work better with `counsel-find-file',
for plain `find-file' it will open a `dired' buffer in addition to
opening the URL.
---
counsel.el | 23 +++++++++++++++++++++++
ivy.el | 11 ++++++++++-
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/counsel.el b/counsel.el
index b6ac36a..6c5a283 100644
--- a/counsel.el
+++ b/counsel.el
@@ -492,6 +492,29 @@ When INITIAL-INPUT is non-nil, use it in the minibuffer
during completion."
:history 'file-name-history
:keymap counsel-find-file-map))
+(defun counsel-github-url-p ()
+ "Return a Github issue URL at point."
+ (when (and (looking-at "#[0-9]+")
+ (or
+ (eq (vc-backend (buffer-file-name)) 'Git)
+ (memq major-mode '(magit-commit-mode))))
+ (let ((url (match-string-no-properties 0))
+ (origin (shell-command-to-string
+ "git remote get-url origin"))
+ user repo)
+ (cond ((string-match "address@hidden:\\([^/]+\\)/\\(.*\\)\\.git$"
+ origin)
+ (setq user (match-string 1 origin))
+ (setq repo (match-string 2 origin)))
+ ((string-match "\\`https://github.com/\\([^/]+\\)/\\(.*\\)$"
+ origin)
+ (setq user (match-string 1 origin))
+ (setq repo (match-string 2 origin))))
+ (when user
+ (setq url (format "https://github.com/%s/%s/issues/%s"
+ user repo (substring url 1)))))))
+(add-to-list 'ivy-ffap-url-functions 'counsel-github-url-p)
+
(defcustom counsel-find-file-ignore-regexp nil
"A regexp of files to ignore while in `counsel-find-file'.
These files are un-ignored if `ivy-text' matches them.
diff --git a/ivy.el b/ivy.el
index 2240e9e..fb251d1 100644
--- a/ivy.el
+++ b/ivy.el
@@ -791,13 +791,22 @@ Call the permanent action if possible."
(move-end-of-line 1)
(ivy--maybe-scroll-history))
+(defvar ivy-ffap-url-functions nil
+ "List of functions that check if the point is on a URL.")
+
(defun ivy--cd-maybe ()
"Check if the current input points to a different directory.
If so, move to that directory, while keeping only the file name."
(when ivy--directory
(let ((input (ivy--input))
url)
- (if (setq url (ffap-url-p input))
+ (if (setq url (or (ffap-url-p input)
+ (with-ivy-window
+ (cl-reduce
+ (lambda (a b)
+ (or a (funcall b)))
+ ivy-ffap-url-functions
+ :initial-value nil))))
(ivy-exit-with-action
(lambda (_)
(funcall ffap-url-fetcher url)))
- [elpa] master 93d1adc 026/272: Properly support matching ignoring order, (continued)
- [elpa] master 93d1adc 026/272: Properly support matching ignoring order, Oleh Krehel, 2016/04/25
- [elpa] master 9a6b5fd 042/272: Add rcirc-mode to swiper-font-lock-ensure-exclude, Oleh Krehel, 2016/04/25
- [elpa] master ec7da3f 075/272: ivy.el (ivy-help-file): Improve location, Oleh Krehel, 2016/04/25
- [elpa] master c76c005 045/272: Add feedback for sole ivy completion., Oleh Krehel, 2016/04/25
- [elpa] master 59c5f16 044/272: Special case empty ivy-count-format completion., Oleh Krehel, 2016/04/25
- [elpa] master 569c11e 017/272: ivy.el (ivy-completion-in-region): Use compact ivy-count-format, Oleh Krehel, 2016/04/25
- [elpa] master d996215 038/272: Add counsel-descbinds, Oleh Krehel, 2016/04/25
- [elpa] master 9ef344d 062/272: use imenu API to jump to position. required by org-mode, Oleh Krehel, 2016/04/25
- [elpa] master 0a9780b 046/272: ivy.el (ivy--recompute-index): Update cl-position logic, Oleh Krehel, 2016/04/25
- [elpa] master 407ce2c 051/272: counsel.el (counsel-list-processes): New command, Oleh Krehel, 2016/04/25
- [elpa] master e3e1f51 052/272: ivy.el (ivy-ffap-url-functions): Customize "C-x C-f M-n",
Oleh Krehel <=
- [elpa] master b39f409 056/272: counsel.el (counsel-unicode-char): Display hex codes in left column, Oleh Krehel, 2016/04/25
- [elpa] master eab714f 054/272: counsel.el (counsel-at-git-issue-p): New defun, Oleh Krehel, 2016/04/25
- [elpa] master 4696b89 057/272: ivy.el (ivy-switch-buffer-other-window): New command, Oleh Krehel, 2016/04/25
- [elpa] master 763d42b 048/272: Initialize `ivy-last` to empty state., Oleh Krehel, 2016/04/25
- [elpa] master c0c0f63 060/272: ivy.el (ivy-read): Fix extra actions for completing-read, Oleh Krehel, 2016/04/25
- [elpa] master 5f4bc14 058/272: counsel.el (counsel-rhythmbox-current-song): Preselect the current song, Oleh Krehel, 2016/04/25
- [elpa] master 2877ae1 063/272: ivy.el (ivy-ignore-buffers): New defcustom, Oleh Krehel, 2016/04/25
- [elpa] master 480cc85 071/272: README.md: Update, Oleh Krehel, 2016/04/25
- [elpa] master 7b08db8 094/272: ivy.el (ivy-next-history-element): Use "\\_<" instead of "\\b", Oleh Krehel, 2016/04/25
- [elpa] master e94f13e 104/272: counsel.el (counsel-imenu): Add :preselect, Oleh Krehel, 2016/04/25