From mboxrd@z Thu Jan 1 00:00:00 1970 From: Samuel Loury Subject: [PATCH] org-git-link.el: Add support for line in org-git-link Date: Fri, 11 Jul 2014 09:14:11 +0200 Message-ID: <87ha2ol64c.fsf@konixwork.cosmo> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5V2M-0004t9-B9 for emacs-orgmode@gnu.org; Fri, 11 Jul 2014 03:14:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X5V2D-0002Ya-7Y for emacs-orgmode@gnu.org; Fri, 11 Jul 2014 03:14:30 -0400 Received: from mail-wg0-x230.google.com ([2a00:1450:400c:c00::230]:43337) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5V2C-0002Xp-TB for emacs-orgmode@gnu.org; Fri, 11 Jul 2014 03:14:21 -0400 Received: by mail-wg0-f48.google.com with SMTP id x13so607514wgg.19 for ; Fri, 11 Jul 2014 00:14:19 -0700 (PDT) Received: from localhost (162.48.7.109.rev.sfr.net. [109.7.48.162]) by mx.google.com with ESMTPSA id a13sm3304383wjs.12.2014.07.11.00.14.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Jul 2014 00:14:18 -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: OrgMode ML --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Hi, I would like to submit a small enhancement of the org-git-link package to add the storing and use of a line third argument. Please find the patch attached to this mail. I hope you'll find it useful. Thanks for your attention. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org-git-link.el-Add-support-for-line-in-org-git-ling.patch Content-Transfer-Encoding: quoted-printable From=207144b05b9d024222cb7e46a370ba3d974ae235af Mon Sep 17 00:00:00 2001 From: Konubinix Date: Fri, 11 Jul 2014 09:10:02 +0200 Subject: [PATCH] org-git-link.el: Add support for line in org-git-ling * org-git-link.el (org-git-open): Jump to the line if provided in the link. (org-git-split-string): Parse a third element of the list and change the er= ror message accordingly. (org-git-create-git-link): Accept the third optional line argument. (org-git-store-link): call `org-git-create-git-link' with the current line number. =2D-- contrib/lisp/org-git-link.el | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/contrib/lisp/org-git-link.el b/contrib/lisp/org-git-link.el index 7d95bbb..ad0ce71 100644 =2D-- a/contrib/lisp/org-git-link.el +++ b/contrib/lisp/org-git-link.el @@ -98,10 +98,12 @@ (let* ((strlist (org-git-split-string str)) (filepath (first strlist)) (commit (second strlist)) + (line (third strlist)) (dirlist (org-git-find-gitdir (file-truename filepath))) (gitdir (first dirlist)) (relpath (second dirlist))) =2D (org-git-open-file-internal gitdir (concat commit ":" relpath)))) + (org-git-open-file-internal gitdir (concat commit ":" relpath)) + (when line (goto-line (string-to-int line))))) =20 ;; Utility functions (file names etc) @@ -141,16 +143,19 @@ ;; splitting the link string =20 ;; Both link open functions are called with a string of =2D;; consisting of two parts separated by a double colon (::). +;; consisting of three parts separated by a double colon (::). (defun org-git-split-string (str) =2D "Given a string of the form \"str1::str2\", return a list of =2D two substrings \'(\"str1\" \"str2\"). If the double colon is mising, t= ake str2 to be the empty string." + "Given a string of the form \"str1::str2::str3\", return a list of + three substrings \'(\"str1\" \"str2\" \"str3\"). If there are less +than two double colons, str2 and/or str3 may be set the empty string." (let ((strlist (split-string str "::"))) (cond ((=3D 1 (length strlist)) =2D (list (car strlist) "")) + (list (car strlist) "" "")) ((=3D 2 (length strlist)) + (append strlist (list ""))) + ((=3D 3 (length strlist)) strlist) =2D (t (error "org-git-split-string: only one :: allowed: %s" str)= )))) + (t (error "org-git-split-string: only one or two :: allowed: %s"= str))))) =20 ;; finding the file name part of a commit (defun org-git-link-filename (str) @@ -168,22 +173,24 @@ (concat branch "@{" timestring "}")) =20 =20 =2D(defun org-git-create-git-link (file) +(defun org-git-create-git-link (file &optional line) "Create git link part to file at specific time" (interactive "FFile: ") (let* ((gitdir (first (org-git-find-gitdir (file-truename file)))) (branchname (org-git-get-current-branch gitdir)) (timestring (format-time-string "%Y-%m-%d" (current-time)))) =2D (concat "git:" file "::" (org-git-create-searchstring branchname tim= estring)))) + (concat "git:" file "::" (org-git-create-searchstring branchname times= tring) + (if line (format "::%s" line) "")))) =20 (defun org-git-store-link () "Store git link to current file." (when (buffer-file-name) =2D (let ((file (abbreviate-file-name (buffer-file-name)))) + (let ((file (abbreviate-file-name (buffer-file-name))) + (line (line-number-at-pos))) (when (org-git-gitrepos-p file) (org-store-link-props :type "git" =2D :link (org-git-create-git-link file)))))) + :link (org-git-create-git-link file line)))))) =20 (add-hook 'org-store-link-functions 'org-git-store-link) =20 =2D-=20 2.0.0.rc2 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable =2D-=20 Konubinix GPG Key : 7439106A Fingerprint: 5993 BE7A DA65 E2D9 06CE 5C36 75D2 3CED 7439 106A --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJTv47DAAoJEHXSPO10ORBqGdwH/2pqtz9pf0qNzyGCd/1hLGVe wQr3vrtzp4mxkO32NxwNaRYL9nU1R/DsRqUCrhri0UHfgj28/kgJIe2SR5V9mGTc PLuniyAqX5D2idkhoayPfsDRp3YwUheKgtiSBmnSkUNxNBa8aSnqM87oSAEmL+0e jHcdHj26ITU054zg2r8A9eRtVEmjg6BtSDWBsmjl0pCsn2aEqHFx+5uR9GXrfx9d R/qag11/EqvvAA+M5W4a+TT02mq55vjF8jTUIxGyQPs8gEQ7GKk5NJqHR02mDcy+ qHflQKQSMJdU6IwNORnZZSDwkol3M9rtL8F/vx+87p5Nmh0Z8HwPQwbYZextGrc= =LfDz -----END PGP SIGNATURE----- --==-=-=--