emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: David Holm <dholmster@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH v1 3/4] contrib/lisp/org-annotate-file.el improvements
Date: Sat, 15 Mar 2014 19:18:55 +0100	[thread overview]
Message-ID: <CAAw2GXsZqpDamd1i-8psSu9EfrnrAgxH1HfcBne635O16D+1TA@mail.gmail.com> (raw)


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

The third patch provides the bulk of the change.  It extracts most of the
functionality of `org-annotate-file-show-section` into
`org-annotate-file-annotate` and now just acts as a wrapper around it for
setting up and returning the buffer to the caller.

[-- Attachment #1.2: Type: text/html, Size: 276 bytes --]

[-- Attachment #2: 0003-Allow-the-user-to-control-the-annotation-buffer.patch --]
[-- Type: application/octet-stream, Size: 4821 bytes --]

From a49666c0fc7980ee335ad78a5987feb532390869 Mon Sep 17 00:00:00 2001
From: David Holm <dholmster@gmail.com>
Date: Sat, 15 Mar 2014 17:21:50 +0100
Subject: [PATCH 3/4] Allow the user to control the annotation buffer

* contrib/lisp/org-annotate-file.el (org-annotate-file,
org-annotate-file-show-section): Return the annotation buffer from
`org-annotate-file-show-section` so that the user can decide how to
display it.

When adding an annotation using org-file-annotate, the buffer would
always be opened in the current window.  By not making the buffer
current and instead returning it from `org-annotate-file-show-section`
the user can control how to display it.

For instance, it can be opened in a popup window using popwin:

    (popwin:display-buffer-1 (org-annotate-file-show-section storage-file)
                             :default-config-keywords '(:position :bottom))

The function `org-annotate-file` will still work as before and open
the buffer in the current window.
---
 contrib/lisp/org-annotate-file.el | 65 ++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 28 deletions(-)

diff --git a/contrib/lisp/org-annotate-file.el b/contrib/lisp/org-annotate-file.el
index b5c1f5d..6bea7ef 100644
--- a/contrib/lisp/org-annotate-file.el
+++ b/contrib/lisp/org-annotate-file.el
@@ -84,40 +84,49 @@ Trim whitespace at beginning and end of STRING and replace any
     string))
 
 (defun org-annotate-file ()
-  "Put a section for the current file into your annotation file."
+  "Visit `org-annotate-file-storage-file` and add a new annotation section.
+The annotation is opened at the new section which will be referencing
+the point in the current file."
   (interactive)
   (unless (buffer-file-name)
     (error "This buffer has no associated file!"))
-  (org-annotate-file-show-section org-annotate-file-storage-file))
-
-(defun org-annotate-file-show-section (storage-file &optional buffer)
-  "Visit the buffer named STORAGE-FILE.
-The cursor will be placed at the relevant section.  If BUFFER is
-  specified the annotation will be referencing it, otherwise the
-  current buffer is used."
-  (let* ((filename (abbreviate-file-name (or buffer (buffer-file-name))))
-         (line (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
-         (link (org-make-link-string (concat "file:" filename) filename))
+  (switch-to-buffer
+   (org-annotate-file-show-section org-annotate-file-storage-file)))
+
+(defun org-annotate-file-show-section (storage-file &optional annotated-buffer)
+  "Add or show annotation entry in STORAGE-FILE and return the buffer.
+The annotation will link to ANNOTATED-BUFFER if specified,
+  otherwise the current buffer is used."
+  (let ((filename (abbreviate-file-name (or annotated-buffer
+					    (buffer-file-name))))
+        (line (buffer-substring-no-properties (point-at-bol) (point-at-eol)))
+        (annotation-buffer (find-file-noselect storage-file)))
+    (with-current-buffer annotation-buffer
+      (org-annotate-file-annotate filename line))
+    annotation-buffer))
+
+(defun org-annotate-file-annotate (filename line)
+  "Add annotation for FILENAME at LINE using current buffer."
+  (let* ((link (org-make-link-string (concat "file:" filename) filename))
          (search-link (org-make-link-string
                        (concat "file:" filename "::" line)
-                               (org-annotate-file-ellipsify-desc line))))
-    (with-current-buffer (find-file storage-file)
-      (unless (eq major-mode 'org-mode)
-        (org-mode))
-      (goto-char (point-min))
-      (widen)
-      (when org-annotate-file-always-open
-        (show-all))
+		       (org-annotate-file-ellipsify-desc line))))
+    (unless (eq major-mode 'org-mode)
+      (org-mode))
+    (goto-char (point-min))
+    (widen)
+    (when org-annotate-file-always-open
+      (show-all))
+    (unless (search-forward-regexp
+	     (concat "^* " (regexp-quote link)) nil t)
+      (org-annotate-file-add-upper-level link))
+    (beginning-of-line)
+    (org-narrow-to-subtree)
+    ;; deal with a '::' search if need be
+    (when org-annotate-file-add-search
       (unless (search-forward-regexp
-               (concat "^* " (regexp-quote link)) nil t)
-        (org-annotate-file-add-upper-level link))
-      (beginning-of-line)
-      (org-narrow-to-subtree)
-      ;; deal with a '::' search if need be
-      (when org-annotate-file-add-search
-        (unless (search-forward-regexp
-                 (concat "^** " (regexp-quote search-link)) nil t)
-          (org-annotate-file-add-second-level search-link))))))
+	       (concat "^** " (regexp-quote search-link)) nil t)
+	(org-annotate-file-add-second-level search-link)))))
 
 (defun org-annotate-file-add-upper-level (link)
   "Add and link heading to LINK."
-- 
1.9.0


                 reply	other threads:[~2014-03-15 18:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAw2GXsZqpDamd1i-8psSu9EfrnrAgxH1HfcBne635O16D+1TA@mail.gmail.com \
    --to=dholmster@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).