emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-git-link.el: Add support for line in org-git-link
@ 2014-07-11  7:14 Samuel Loury
  2014-07-27 14:16 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Samuel Loury @ 2014-07-11  7:14 UTC (permalink / raw)
  To: OrgMode ML


[-- Attachment #1.1: Type: text/plain, Size: 233 bytes --]

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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-org-git-link.el-Add-support-for-line-in-org-git-ling.patch --]
[-- Type: text/x-diff, Size: 3811 bytes --]

From 7144b05b9d024222cb7e46a370ba3d974ae235af Mon Sep 17 00:00:00 2001
From: Konubinix <konubinix@gmail.com>
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 error
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.
---
 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
--- 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)))
-    (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)))))
 
 \f
 ;; Utility functions (file names etc)
@@ -141,16 +143,19 @@
 ;; splitting the link string
 
 ;; Both link open functions are called with a string of
-;; consisting of two parts separated by a double colon (::).
+;; consisting of three parts separated by a double colon (::).
 (defun org-git-split-string (str)
-  "Given a string of the form \"str1::str2\", return a list of
-  two substrings \'(\"str1\" \"str2\"). If the double colon is mising, take 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 ((= 1 (length strlist))
-           (list (car strlist) ""))
+           (list (car strlist) "" ""))
           ((= 2 (length strlist))
+           (append strlist (list "")))
+          ((= 3 (length strlist))
            strlist)
-          (t (error "org-git-split-string: only one :: allowed: %s" str)))))
+          (t (error "org-git-split-string: only one or two :: allowed: %s" str)))))
 
 ;; finding the file name part of a commit
 (defun org-git-link-filename (str)
@@ -168,22 +173,24 @@
   (concat branch "@{" timestring "}"))
 
 
-(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))))
-    (concat "git:" file "::" (org-git-create-searchstring branchname timestring))))
+    (concat "git:" file "::" (org-git-create-searchstring branchname timestring)
+	    (if line (format "::%s" line) ""))))
 
 (defun org-git-store-link ()
   "Store git link to current file."
   (when (buffer-file-name)
-    (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"
-	 :link (org-git-create-git-link file))))))
+	 :link (org-git-create-git-link file line))))))
 
 (add-hook 'org-store-link-functions 'org-git-store-link)
 
-- 
2.0.0.rc2


[-- Attachment #1.3: Type: text/plain, Size: 104 bytes --]

-- 
Konubinix
GPG Key    : 7439106A
Fingerprint: 5993 BE7A DA65 E2D9 06CE  5C36 75D2 3CED 7439 106A

[-- Attachment #2: Type: application/pgp-signature, Size: 472 bytes --]

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

end of thread, other threads:[~2014-07-28 17:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-11  7:14 [PATCH] org-git-link.el: Add support for line in org-git-link Samuel Loury
2014-07-27 14:16 ` Bastien

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).