emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] following org links to gnus messages and window management


From: Eric Abrahamsen
Subject: Re: [O] following org links to gnus messages and window management
Date: Thu, 20 Mar 2014 12:14:50 +0800
User-agent: Gnus/5.13001 (Ma Gnus v0.10) Emacs/24.3 (gnu/linux)

Alan Schmitt <address@hidden> writes:

> Hi Bastien,
>
> Bastien <address@hidden> writes:
>
>>> - if not, is there a way to copy a link then open it using the
>>>   minibuffer (I would then do the switch to screen 0 manually)?
>>
>> This does not use the minibuffer but you could add that:
>>
>> (progn
>>   (org-next-link)
>>   (org-open-link-from-string
>>    (org-element-property :raw-link (org-element-link-parser))))
>
> This was most helpful: I just need to copy the link I want to follow, go
> to the first screen, and interactively call `org-open-link-from-string'.
> This works great for the moment.
>
>>> - finally, do you have alternative window management options to suggest
>>>   that would work well with following links to gnus messages?
>>
>> Well, all I can think of now is
>>
>> (setq org-agenda-window-setup 'other-frame)
>
> Thanks, but I'm trying to avoid using several frames. (OS
> X unfortunately does not come with a window manager that I like ...)
>
> Thanks again,
>
> Alan

I have a setup that's probably more complicated than what you want, but
maybe you'll find something interesting in it. The problem is, you need
to somehow specify when or under what conditions you do away with the
opened windows and return to your org file or agenda. In my case, I use
the following to answer emails. When I open the link it stores the
current window configuration, and when the email is sent it triggers the
restore.

I believe I've confused myself slightly while trying to set up
interactive vs non-interactive versions, but so far I've never wanted to
use it non-interactively, so it works fine.

#+BEGIN_SRC org

(defvar org-mail-window-conf nil
  "Save org-buffer window configuration here, for later
  restoration.")

(defun org-mail-restore-after-send ()
  (gnus-summary-exit nil t)
  (when (window-configuration-p org-mail-window-conf)
    (set-window-configuration org-mail-window-conf))
  ; Should check here that we actually made it back to the org
  ; heading. Could save an ID prop on the heading and check for that.
  (call-interactively 'org-agenda-todo))

(defun org-mail-handle-mail (&optional interactive-p)
  "Handle mail-related links for current headline."
  (interactive "p")
  (unless (org-back-to-heading t)
    (error "Not in an org item"))
  (when interactive-p
    (setq org-mail-window-conf (current-window-configuration)))
  (let (message mailto)
    (while (re-search-forward org-any-link-re (line-end-position) t) 
      (let ((addr (or (match-string-no-properties 2)
                      (match-string-no-properties 0))))
        (cond
         ((string-match "^<?gnus:" addr)
          (push (substring addr (match-end 0)) message))
         ((string-match "^<?mailto:"; addr)
          (push (substring addr (match-end 0)) mailto))
         ((and (featurep 'bbdb)
               (string-match-p "^<?bbdb:" addr))
          (with-current-buffer bbdb-buffer-name
            (let ((recs bbdb-records))
              (org-open-link-from-string addr)
              (let ((mail (bbdb-mail-address (bbdb-current-record))))
                (bbdb-display-records recs)
                (push mail mailto))))))))
    (cond
     (message
      (org-gnus-open (org-link-unescape (car message)))
      (call-interactively
       'gnus-summary-wide-reply-with-original)
      (when mailto
        (message-goto-to)
        (insert ", ")
        (insert (mapconcat 'identity mailto ", "))
        (message-goto-body))
      (add-to-list 'message-exit-actions
                   'org-mail-restore-after-send t))
     (mailto
      (compose-mail (mapconcat 'identity mailto ", ")
                    nil nil nil nil nil nil 
                    'org-mail-restore-after-send))
     (t
      (error "No mail-related links in headline")))))

(defun org-mail-handle-mail-agenda ()
  "Examine item at point for mail-related links, and handle them."
  (interactive)
  (org-agenda-check-type t 'agenda 'timeline 'todo 'tags)
  (org-agenda-check-no-diary)
  (let* ((marker (or (org-get-at-bol 'org-hd-marker)
                     (org-agenda-error)))
         (buffer (marker-buffer marker))
         (pos (marker-position marker)))
    (setq org-mail-window-conf (current-window-configuration))
    (with-current-buffer buffer
      (widen)
      (goto-char pos)
      (org-mail-handle-mail))))

(eval-after-load 'org-agenda
  '(org-defkey org-agenda-mode-map (kbd "H") 'org-mail-handle-mail-agenda))
#+END_SRC





reply via email to

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