emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Fast linking to files in private git repos through a hyperlink
@ 2012-04-19 11:24 Dov Grobgeld
  2012-04-19 18:49 ` Karl Voit
  2012-04-20 12:01 ` Bastien
  0 siblings, 2 replies; 7+ messages in thread
From: Dov Grobgeld @ 2012-04-19 11:24 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2007 bytes --]

I thought I would share the following hack that I did with git.

In my org-mode notebook I often find myself references files that reside in
various private git repos. So far I have referenced these either by just
writing their name or giving a full path. But giving the full path is
disruptive and if the repo moves it will no longer work. So I added a hack
to make the following hyperlink work git:myrepo::myfile . When opening it
the following happens:

- myrepo is looked up in the emacs hash my-git-repos and mapped to the path
of a git repo root.
- git-find-file-in-repo searches for the the file myfile in the the repo
repo

Here's the code for org-git-hyperlink.el:

(require 'org)

(org-add-link-type "git" 'org-git-hyperlink-open)

(defun org-git-hyperlink-open (path)
  "Visit the file in learning-git"
  (let* ((parts (split-string path "::"))
         (repo-name (car parts))
         (filename (cadr parts))
         (repo (gethash repo-name my-git-repos))
         )
    (git-find-file-in-repo repo filename)))
(org-git-hyperlink-open "learning::PointPatternMatching.py")
;;; org-learning.el ends here

(provide 'org-git-hyperlink)
;;; org-git-hyperlink.el ends here

The code for git-find-file-in-repo is here:

https://github.com/hjz/emacs/blob/master/jz/git-find-file.el

with the following addition:

(defun git-find-file-in-repo (root file-name)
  "Prompt with a completing list of all files in the project to find one."
  (interactive)
  (let* ((project-files (ffip-project-files root))
         (files (delete-dups (mapcar 'car project-files)))
         (file-paths (delq 'nil (mapcar '(lambda (file-cons)
                                           (when (string= file-name (car
file-cons))
                                             (cdr file-cons)))
project-files)))
         (file-path (if (cdr file-paths)
                        (ffip-completing-read "Disambiguate: " file-paths)
                      (car file-paths))))
    (find-file (concat root file-path))))

Regards,
Dov

[-- Attachment #2: Type: text/html, Size: 2602 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-04-26 18:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-19 11:24 Fast linking to files in private git repos through a hyperlink Dov Grobgeld
2012-04-19 18:49 ` Karl Voit
2012-04-20 12:01 ` Bastien
2012-04-21 21:19   ` Dov Grobgeld
2012-04-26 14:00     ` Bastien
2012-04-26 18:06       ` Dov Grobgeld
2012-04-26 18:32         ` Samuel Wales

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).