From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dov Grobgeld Subject: Fast linking to files in private git repos through a hyperlink Date: Thu, 19 Apr 2012 14:24:23 +0300 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d0444ef07f6afae04be06695a Return-path: Received: from eggs.gnu.org ([208.118.235.92]:50714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKpTU-0004pS-1Z for emacs-orgmode@gnu.org; Thu, 19 Apr 2012 07:24:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKpTO-0006De-M9 for emacs-orgmode@gnu.org; Thu, 19 Apr 2012 07:24:31 -0400 Received: from mail-ob0-f169.google.com ([209.85.214.169]:51046) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKpTO-0006D1-Cm for emacs-orgmode@gnu.org; Thu, 19 Apr 2012 07:24:26 -0400 Received: by obbeh20 with SMTP id eh20so7079653obb.0 for ; Thu, 19 Apr 2012 04:24:23 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode --f46d0444ef07f6afae04be06695a Content-Type: text/plain; charset=UTF-8 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 --f46d0444ef07f6afae04be06695a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I thought I woul= d share the following hack that I did with git.

In my org-mode note= book I often find myself references files that reside in various private gi= t repos. So far I have referenced these either by just writing their name o= r giving a full path. But giving the full path is disruptive and if the rep= o moves it will no longer work. So I added a hack to make the following hyp= erlink 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 fi= le myfile in the the repo repo

Here's the code for org-git-hyper= link.el:

(require 'org)

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

(defun org-git-hyperlink-open (path)
=C2=A0 &q= uot;Visit the file in learning-git"
=C2=A0 (let* ((parts (split-str= ing path "::"))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (repo-name (car parts))=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (filename (cadr parts))=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (repo (gethash repo-name= my-git-repos))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 )
= =C2=A0=C2=A0=C2=A0 (git-find-file-in-repo repo filename)))
(org-git-hype= rlink-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<= /a>

with the following addition:

(defun git-find-file-in-repo (root = file-name)
=C2=A0 "Prompt with a completing list of all files in th= e project to find one."
=C2=A0 (interactive)
=C2=A0 (let* ((proj= ect-files (ffip-project-files root))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (files (delete-dups (mapca= r 'car project-files)))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (file-paths (delq 'nil (mapcar '(lambda (file-cons)
=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (when (string=3D file-name (car file-cons))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (cdr file-cons))) project-files)))<= br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (file-path (if (cdr fil= e-paths)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= (ffip-completing-read "Disambiguate: " file-paths)
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (car file-paths))))
=C2=A0=C2=A0=C2=A0 (find-file (concat root file-path))))

Regards,Dov

--f46d0444ef07f6afae04be06695a--