emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-orgmode@gnu.org
Subject: Re: following org links to gnus messages and window management
Date: Thu, 20 Mar 2014 12:14:50 +0800	[thread overview]
Message-ID: <87k3bp4ibp.fsf@ericabrahamsen.net> (raw)
In-Reply-To: m238ie1n2p.fsf@polytechnique.org

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> Hi Bastien,
>
> Bastien <bzg@gnu.org> 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	other threads:[~2014-03-20  4:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-19  8:01 following org links to gnus messages and window management Alan Schmitt
2014-03-19 10:18 ` Bastien
2014-03-19 10:48   ` Alan Schmitt
2014-03-20  4:14     ` Eric Abrahamsen [this message]
2014-03-20 14:27       ` Alan Schmitt

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=87k3bp4ibp.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --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).