emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Links Drawer
@ 2014-06-09 15:19 Leonard Randall
  0 siblings, 0 replies; only message in thread
From: Leonard Randall @ 2014-06-09 15:19 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 3954 bytes --]

Hi all,
In a few functions that I use for organizing my research, I use links
drawers. This enables me to write functions that automatically insert links
in all entries matching particular criteria, or insert links directly from
the headline or anywhere else in the entry. To do this I wrote a couple of
functions. The first function is nearly identical to
org-insert-properties-drawer (I only changed a bit of regexp). It simply
inserts a LINKS drawer near the top of the entry below any clocking,
scheduling, or deadline or PROPERTIES info. It is not for interactive use.
The the other searches for a links drawer in the current entry and inserts
one if none is found. It  then inserts a link in the drawer using

Anyway I thought they might be useful for others, and I wondered if people
thought that they should be part of org-mode.  Here is the code. Don't
hesitate to give any suggestions.

(defun my-org-insert-links-drawer ()
  "Insert a links drawer near the beginning of the current entry.
        Inserts drawer near beginning of entry after scheduling, deadline
        and clocking info and after standard logging, property and clock
  (org-back-to-heading t)
  (looking-at org-outline-regexp)
  (let ((indent (if org-adapt-indentation
                    (- (match-end 0) (match-beginning 0))
        (beg (point))
        (re (concat "^[ \t]*" org-keyword-time-regexp))
        end hiddenp)
    (setq end (point))
    (goto-char beg)
    (while (re-search-forward re end t))
    (setq hiddenp (outline-invisible-p))
    (end-of-line 1)
    (and (equal (char-after) ?\n) (forward-char 1))
    (while (looking-at "^[
      (if (member (match-string 1) '("CLOCK:" ":END:"))
          ;; just skip this line
          (beginning-of-line 2)
        ;; Drawer start, find the end
        (re-search-forward "^\\*+ \\|^[ \t]*:END:" nil t)
        (beginning-of-line 1)))
    (skip-chars-backward " \t\n\r")
    (if (and (eq (char-before) ?*) (not (eq (char-after) ?\n)))
        (forward-char 1))
    (goto-char (point-at-eol))
    (let ((inhibit-read-only t)) (insert "\n:LINKS:\n:END:"))
    (beginning-of-line 0)
    (org-indent-to-column indent)
    (beginning-of-line 2)
    (org-indent-to-column indent)
    (beginning-of-line 0)
    (if hiddenp
          (org-back-to-heading t)
      (org-flag-drawer t))))

(defun my-org-insert-link-in-drawer (&optional complete-file link-location
  "Find or create links drawer then insert link with `org-insert-link'.
are passsed on to `org-insert-link'.  See its documentation for
information on how these arguments are handled."
  ;; make sure that we are currently in an entry.
  (if (not (org-before-first-heading-p))
      ;; look for links drawer.
        (org-back-to-heading t)
        (let ((beg (point))
              end hiddenp)
          (setq end (point))
          (backward-char 1)
          (setq hiddenp (outline-invisible-p))
          (goto-char beg)
          (unless (and (re-search-forward "[ \t]*:LINKS:[ \t]*$" end t)
                       (re-search-forward "[ \t]*:END:[ \t]*$" end t))
            ;; if no links drawer found create one.
          ;; go to links drawer.
          (goto-char beg)
          (re-search-forward "[ \t]*:LINKS:[ \t]*$")
          ;; open new line and insert link.
          (org-insert-link complete-file link-location default-description)
          (if hiddenp
    ;; Give error if before first heading.
    (error "Before first heading")))

All best,

[-- Attachment #2: Type: text/html, Size: 4955 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-06-09 15:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-09 15:19 Links Drawer Leonard Randall

Code repositories for project(s) associated with this public inbox


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