annotate lisp/org/org-irc.el @ 97384:60d1b6f5616e

*** empty log message ***
author Glenn Morris <rgm@gnu.org>
date Sun, 10 Aug 2008 00:59:33 +0000
parents adc2dffbdfc3
children e1cc41b9282d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1 ;;; org-irc.el --- Store links to IRC sessions
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
2 ;;
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
3 ;; Copyright (C) 2008 Free Software Foundation, Inc.
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
4 ;;
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
5 ;; Author: Philip Jackson <emacs@shellarchive.co.uk>
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
6 ;; Keywords: erc, irc, link, org
97027
adc2dffbdfc3 2008-07-25 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 96975
diff changeset
7 ;; Version: 6.06b
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
8 ;;
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
10 ;;
94676
ba3167bc4143 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94414
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94676
ba3167bc4143 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94414
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
ba3167bc4143 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94414
diff changeset
14 ;; (at your option) any later version.
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
15
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
19 ;; GNU General Public License for more details.
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
20
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94676
ba3167bc4143 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94414
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
23
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
24 ;;; Commentary:
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
25
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
26 ;; This file implements links to an IRC session from within Org-mode.
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
27 ;; Org-mode loads this module by default - if this is not what you want,
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
28 ;; configure the variable `org-modules'.
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
29 ;;
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
30 ;; Please customize the variable `org-default-extensions' to select
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
31 ;; extensions you would like to use, and to deselect those which you don't
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
32 ;; want.
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
33 ;;
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
34 ;; Please note that at the moment only ERC is supported. Other clients
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
35 ;; shouldn't be difficult to add though.
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
36 ;;
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
37 ;; Then set `org-irc-link-to-logs' to non-nil if you would like a
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
38 ;; file:/ type link to be created to the current line in the logs or
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
39 ;; to t if you would like to create an irc:/ style link.
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
40 ;;
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
41 ;; Links within an org buffer might look like this:
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
42 ;;
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
43 ;; [[irc:/irc.freenode.net/#emacs/bob][chat with bob in #emacs on freenode]]
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
44 ;; [[irc:/irc.freenode.net/#emacs][#emacs on freenode]]
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
45 ;; [[irc:/irc.freenode.net/]]
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
46 ;;
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
47 ;; If, when the resulting link is visited, there is no connection to a
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
48 ;; requested server then one will be created.
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
49
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
50 ;;; Code:
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
51
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
52 (require 'org)
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
53
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
54 ;; Declare the function fomr ERC that we use.
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
55 (declare-function erc-current-logfile "erc-log" (&optional buffer))
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
56 (declare-function erc-prompt "erc" ())
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
57 (declare-function erc-default-target "erc" ())
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
58 (declare-function erc-channel-p "erc" (channel))
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
59 (declare-function erc-buffer-filter "erc" (predicate &optional proc))
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
60 (declare-function erc-server-buffer "erc" ())
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
61 (declare-function erc-get-server-nickname-list "erc" ())
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
62 (declare-function erc-cmd-JOIN "erc" (channel &optional key))
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
63
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
64 (defvar org-irc-client 'erc
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
65 "The IRC client to act on.")
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
66 (defvar org-irc-link-to-logs nil
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
67 "Non-nil will store a link to the logs, nil will store an irc: style link.")
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
68
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
69 (defvar erc-default-port) ; dynamically scoped from erc.el
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
70 (defvar erc-session-port) ; dynamically scoped form erc-backend.el
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
71 (defvar erc-session-server) ; dynamically scoped form erc-backend.el
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
72
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
73 ;; Generic functions/config (extend these for other clients)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
74
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
75 (add-to-list 'org-store-link-functions 'org-irc-store-link)
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
76
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
77 (org-add-link-type "irc" 'org-irc-visit nil)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
78
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
79 (defun org-irc-visit (link)
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
80 "Parse LINK and dispatch to the correct function based on the client found."
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
81 (let ((link (org-irc-parse-link link)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
82 (cond
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
83 ((eq org-irc-client 'erc)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
84 (org-irc-visit-erc link))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
85 (t
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
86 (error "erc only known client")))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
87
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
88 (defun org-irc-parse-link (link)
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
89 "Parse an IRC LINK and return the attributes found.
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
90 Parse a LINK that looks like server:port/chan/user (port, chan
94767
8634b4393320 (org-irc-parse-link): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 94676
diff changeset
91 and user being optional) and return any of the port, channel or user
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
92 attributes that are found."
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
93 (let* ((parts (split-string link "/" t))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
94 (len (length parts)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
95 (when (or (< len 1) (> len 3))
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
96 (error "Failed to parse link needed 1-3 parts, got %d" len))
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
97 (setcar parts (split-string (car parts) ":" t))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
98 parts))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
99
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
100 ;;;###autoload
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
101 (defun org-irc-store-link ()
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
102 "Dispatch to the appropriate function to store a link to an IRC session."
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
103 (cond
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
104 ((eq major-mode 'erc-mode)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
105 (org-irc-erc-store-link))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
106
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
107 (defun org-irc-elipsify-description (string &optional after)
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
108 "Remove unnecessary white space from STRING and add ellipses if necessary.
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
109 Strip starting and ending white space from STRING and replace any
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
110 chars that the value AFTER with '...'"
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
111 (let* ((after (number-to-string (or after 30)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
112 (replace-map (list (cons "^[ \t]*" "")
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
113 (cons "[ \t]*$" "")
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
114 (cons (concat "^\\(.\\{" after
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
115 "\\}\\).*") "\\1..."))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
116 (mapc (lambda (x)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
117 (when (string-match (car x) string)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
118 (setq string (replace-match (cdr x) nil nil string))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
119 replace-map)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
120 string))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
121
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
122 ;; ERC specific functions
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
123
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
124 (defun org-irc-erc-get-line-from-log (erc-line)
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
125 "Find the best line to link to from the ERC logs given ERC-LINE as a start.
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
126 If the user is on the ERC-prompt then search backward for the
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
127 first non-blank line, otherwise return the current line. The
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
128 result is a cons of the filename and search string."
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
129 (erc-save-buffer-in-logs)
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
130 (require 'erc-log)
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
131 (with-current-buffer (find-file-noselect (erc-current-logfile))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
132 (goto-char (point-max))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
133 (list
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
134 (abbreviate-file-name buffer-file-name)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
135 ;; can we get a '::' part?
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
136 (if (string= erc-line (erc-prompt))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
137 (progn
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
138 (goto-char (point-at-bol))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
139 (when (search-backward-regexp "^[^ ]" nil t)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
140 (buffer-substring-no-properties (point-at-bol)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
141 (point-at-eol))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
142 (when (search-backward erc-line nil t)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
143 (buffer-substring-no-properties (point-at-bol)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
144 (point-at-eol)))))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
145
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
146 (defun org-irc-erc-store-link ()
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
147 "Store a link to the IRC log file or the session itself.
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
148 Depending on the variable `org-irc-link-to-logs' store either a
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
149 link to the log file for the current session or an irc: link to
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
150 the session itself."
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
151 (require 'erc-log)
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
152 (if org-irc-link-to-logs
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
153 (let* ((erc-line (buffer-substring-no-properties
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
154 (point-at-bol) (point-at-eol)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
155 (parsed-line (org-irc-erc-get-line-from-log erc-line)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
156 (if (erc-logging-enabled nil)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
157 (progn
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
158 (org-store-link-props
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
159 :type "file"
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
160 :description (concat "'" (org-irc-elipsify-description
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
161 (cadr parsed-line) 20)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
162 "' from an IRC conversation")
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
163 :link (concat "file:" (car parsed-line) "::"
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
164 (cadr parsed-line)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
165 t)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
166 (error "This ERC session is not being logged")))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
167 (let* ((link-text (org-irc-get-erc-link))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
168 (link (org-irc-parse-link link-text)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
169 (if link-text
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
170 (progn
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
171 (org-store-link-props
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
172 :type "irc"
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
173 :link (org-make-link "irc:/" link-text)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
174 :description (concat "irc session '" link-text "'")
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
175 :server (car (car link))
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
176 :port (or (string-to-number (cadr (pop link))) erc-default-port)
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
177 :nick (pop link))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
178 t)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
179 (error "Failed to create ('irc:/' style) ERC link")))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
180
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
181 (defun org-irc-get-erc-link ()
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
182 "Return an org compatible irc:/ link from an ERC buffer."
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
183 (let* ((session-port (if (numberp erc-session-port)
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
184 (number-to-string erc-session-port)
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
185 erc-session-port))
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
186 (link (concat erc-session-server ":" session-port)))
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
187 (concat link "/"
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
188 (if (and (erc-default-target)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
189 (erc-channel-p (erc-default-target))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
190 (car (get-text-property (point) 'erc-data)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
191 ;; we can get a nick
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
192 (let ((nick (car (get-text-property (point) 'erc-data))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
193 (concat (erc-default-target) "/" nick))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
194 (erc-default-target)))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
195
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
196 (defun org-irc-get-current-erc-port ()
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
197 "Return the current port as a number.
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
198 Return the current port number or, if none is set, return the ERC
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
199 default."
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
200 (cond
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
201 ((stringp erc-session-port)
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
202 (string-to-number erc-session-port))
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
203 ((numberp erc-session-port)
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
204 erc-session-port)
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
205 (t
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
206 erc-default-port)))
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
207
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
208 (defun org-irc-visit-erc (link)
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
209 "Visit an ERC buffer based on criteria found in LINK."
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
210 (require 'erc)
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
211 (require 'erc-log)
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
212 (let* ((server (car (car link)))
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
213 (port (or (string-to-number (cadr (pop link))) erc-default-port))
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
214 (server-buffer)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
215 (buffer-list
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
216 (erc-buffer-filter
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
217 (lambda nil
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
218 (let ((tmp-server-buf (erc-server-buffer)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
219 (and tmp-server-buf
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
220 (with-current-buffer tmp-server-buf
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
221 (and
94414
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
222 (eq (org-irc-get-current-erc-port) port)
d86cb59eea9f 2008-04-27 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 93141
diff changeset
223 (string= erc-session-server server)
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
224 (setq server-buffer tmp-server-buf)))))))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
225 (if buffer-list
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
226 (let ((chan-name (pop link)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
227 ;; if we got a channel name then switch to it or join it
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
228 (if chan-name
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
229 (let ((chan-buf (catch 'found
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
230 (dolist (x buffer-list)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
231 (if (string= (buffer-name x) chan-name)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
232 (throw 'found x))))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
233 (if chan-buf
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
234 (progn
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
235 (switch-to-buffer chan-buf)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
236 ;; if we got a nick, and they're in the chan,
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
237 ;; then start a chat with them
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
238 (let ((nick (pop link)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
239 (when nick
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
240 (if (member nick (erc-get-server-nickname-list))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
241 (progn
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
242 (goto-char (point-max))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
243 (insert (concat nick ": ")))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
244 (error "%s not found in %s" nick chan-name)))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
245 (progn
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
246 (switch-to-buffer server-buffer)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
247 (erc-cmd-JOIN chan-name))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
248 (switch-to-buffer server-buffer)))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
249 ;; no server match, make new connection
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
250 (erc-select :server server :port port))))
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
251
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
252 (provide 'org-irc)
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
253
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
254 ;; arch-tag: 018d7dda-53b8-4a35-ba92-6670939e525a
96044
c1ef445563bb 2008-06-17 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 94767
diff changeset
255
93141
dda2c82177dc Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
256 ;;; org-irc.el ends here