emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/rt-liberation c574376 1/3: Add Org mode integration.


From: ELPA Syncer
Subject: [elpa] externals/rt-liberation c574376 1/3: Add Org mode integration.
Date: Wed, 25 Aug 2021 13:57:18 -0400 (EDT)

branch: externals/rt-liberation
commit c574376cf71f65f2954a2c7800ce6fe2baa36a22
Author: Yoni Rabkin <yoni@rabkins.net>
Commit: Yoni Rabkin <yoni@rabkins.net>

    Add Org mode integration.
---
 doc/rt-liber.texinfo | 36 ++++++++++++++++++++++++++++
 rt-liberation-org.el | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 rt-liberation.el     | 12 ++++++++++
 3 files changed, 116 insertions(+)

diff --git a/doc/rt-liber.texinfo b/doc/rt-liber.texinfo
index bc2a095..352ee3f 100644
--- a/doc/rt-liber.texinfo
+++ b/doc/rt-liber.texinfo
@@ -61,6 +61,7 @@ Extensions
 * Tracking Updates::            Keeping up to date with ticket changes.
 * Batch Operations::            Performing operations on batches of tickets.
 * Local Storage::               Associate arbitrary data with tickets.
+* Org Integration::             Integration with Org mode.
 
 Copying and license
 * Copying::                     The GNU General Public License gives you
@@ -884,6 +885,41 @@ can be extended to associate any arbitrary data with any 
ticket.
 
 
 @c --------------------------------------------------
+@node Org Integration
+@chapter Org Integration
+@cindex Org Integration
+
+@file{rt-liberation-org.el} implements interation with Org Mode.
+
+To enable it first load @file{rt-liberation-org.el}:
+
+@lisp
+(require 'rt-liberation-org)
+@end lisp
+
+This enables two types of RT Org links:
+
+@enumerate
+@item Id link.
+For example, @code{rt:id:12345} links to ticket #12345 in the
+@xref{Ticket Viewer}.  Optionally you can also append history-id for a
+specific ticket section: @code{rt:id:12345/6789} links to section of
+ticket #12345 with history-id 6789.
+
+@item Query link.
+For example, @code{<rt:query:owner = 'nobody' and created > '7 days
+ago'>} runs the query for unowned tickets that were created more than
+a week ago and display the results in the @xref{Ticket Browser}.
+@end enumerate
+
+You may run @code{org-store-link} inside the Ticket Viewer or Ticket
+Browser to store an RT Org link. If you are inside the Ticket Viewer,
+@code{org-store-link} will store a link to the section of the ticket,
+and if you are inside the Ticket Browser, it will store a link to the
+ticket without specifying the section.
+
+
+@c --------------------------------------------------
 @c including the relevant licenses
 @include gpl.texi
 @include fdl.texi
diff --git a/rt-liberation-org.el b/rt-liberation-org.el
new file mode 100644
index 0000000..0259061
--- /dev/null
+++ b/rt-liberation-org.el
@@ -0,0 +1,68 @@
+;;; rt-liberation-org.el --- Org integration for rt-liberation  -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2008-2021 Free Software Foundation, Inc.
+
+;; Author: Yuchen Pei <hi@ypei.me>
+;; Authors: Yoni Rabkin <yrk@gnu.org>
+;; Maintainer: Yoni Rabkin <yrk@gnu.org>
+
+;; This file is a part of rt-liberation.
+ 
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 3 of the
+;; License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public
+;; License along with this program; if not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
+(require 'org)
+(require 'rt-liberation)
+
+(defun rt-org-open (link)
+  "Opens the rt LINK.
+       Open the rt ticket (for links starting with 'id:') or run
+       the query (for links starting with 'query:')."
+  (cond
+   ((string-match "^id:\\([^/]+\\)\\(/\\(.+\\)\\)?" link)
+    (let ((id (match-string 1 link))
+         (history-id (match-string 3 link)))
+      (rt-liber-browse-query (format "id = \"%s\"" id))
+      (rt-liber-browser-move-point-to-ticket id)
+      (rt-liber-ticket-at-point)
+      (when history-id 
+         (rt-liber-viewer2-move-point-to-section history-id))))
+   ((string-match "^query:\\(.+\\)" link)
+    (rt-liber-browse-query (match-string 1 link)))
+   (t (error "Unrecognized link type '%s'" link))))
+
+(defun rt-org-store-link ()
+  "Stores an rt link in ticket-browser or ticker-viewer mode."
+  (let ((ticket (or (get-text-property (point) 'rt-ticket)
+                   rt-liber-ticket-local)))
+    (when ticket
+      (let* ((ticket-id-link (concat "rt:id:" (rt-liber-ticket-id-only 
ticket)))
+            (subject (cdr (assoc "Subject" ticket)))
+            (history-id (alist-get 'id (rt-liber-viewer2-get-section-data)))
+            (link (concat ticket-id-link (if history-id (concat "/" 
history-id) ""))))
+       (org-link-add-props
+        :link link
+        :description subject)
+       link))))
+
+(if (fboundp 'org-link-set-parameters)
+    (org-link-set-parameters "rt"
+                            :follow #'rt-org-open
+                            :store  #'rt-org-store-link)
+  (error "org-link-set-parameters is void. Are you using an old version of 
Org?"))
+
+;;; _
+(provide 'rt-liberation-org)
+;;; rt-liberation-org.el ends here
diff --git a/rt-liberation.el b/rt-liberation.el
index 1140eed..6026483 100644
--- a/rt-liberation.el
+++ b/rt-liberation.el
@@ -1159,6 +1159,18 @@ ASSOC-BROWSER if non-nil should be a ticket browser."
                                               rt-liber-assoc-browser)
     (error "not viewing a ticket")))
 
+(defun rt-liber-viewer2-move-point-to-section (history-id)
+  "Move point to the beginning of section with HISTORY-ID."
+  (let ((current-history-id (alist-get 'id 
(rt-liber-viewer2-get-section-data)))
+       (previous-history-id nil))
+    (while (not (or (string-equal history-id current-history-id)
+                   (eq current-history-id previous-history-id)))
+      (setq previous-history-id current-history-id)
+      (rt-liber-viewer2-next-section-in)
+      (setq current-history-id (alist-get 'id 
(rt-liber-viewer2-get-section-data))))
+    (when (not (string-equal history-id current-history-id))
+      (error "Cannot find section."))))
+
 (defun rt-liber-viewer2-next-section-in ()
   (interactive)
   (when (looking-at rt-liber-viewer2-section-regexp)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]