Mercurial > emacs
annotate lisp/org/org-irc.el @ 93778:e771e6c269d3
Fix last fix.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sun, 06 Apr 2008 20:37:01 +0000 |
parents | dda2c82177dc |
children | d86cb59eea9f |
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 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
2 |
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. |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
4 |
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 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
7 ;; Version: 1.3 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
8 |
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. |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
10 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
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 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
14 ;; any later version. |
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 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
24 ;; Boston, MA 02110-1301, USA. |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
25 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
26 ;;; Commentary: |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
27 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
28 ;; Link to an IRC session. Only ERC has been implemented at the |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
29 ;; moment. |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
30 ;; |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
31 ;; This file is loaded by default whenever org.el is loaded. Please |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
32 ;; customize the variable `org-default-extensions' to select extensions |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
33 ;; you would like to use, and to deselect those which you don't want. |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
34 ;; |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
35 ;; Please note that at the moment only ERC is supported. Other clients |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
36 ;; shouldn't be diffficult to add though. |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
37 ;; |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
38 ;; 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
|
39 ;; 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
|
40 ;; 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
|
41 ;; |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
42 ;; 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
|
43 ;; |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
44 ;; [[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
|
45 ;; [[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
|
46 ;; [[irc:/irc.freenode.net/]] |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
47 ;; |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
48 ;; 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
|
49 ;; requested server then one will be created. |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
50 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
51 ;;; Code: |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
52 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
53 (require 'org) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
54 (require 'erc) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
55 (require 'erc-log) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
56 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
57 (defvar org-irc-client 'erc |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
58 "The IRC client to act on") |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
59 (defvar org-irc-link-to-logs nil |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
60 "non-nil will store a link to the logs, nil will store an irc: style link") |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
61 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
62 (defvar erc-default-port) ; dynamically scoped from erc.el |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
63 (defvar erc-session-port) ; dynamically scoped form erc-backend.el |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
64 (defvar erc-server-announced-name) ; dynamically scoped form erc-backend.el |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
65 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
66 ;; 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
|
67 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
68 (add-to-list 'org-store-link-functions |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
69 'org-irc-store-link) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
70 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
71 (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
|
72 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
73 (defun org-irc-visit (link) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
74 "Dispatch to the correct visit function based on the client" |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
75 (let ((link (org-irc-parse-link link))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
76 (cond |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
77 ((eq org-irc-client 'erc) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
78 (org-irc-visit-erc link)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
79 (t |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
80 (error "erc only known client"))))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
81 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
82 (defun org-irc-parse-link (link) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
83 "Get a of irc link attributes where `link' looks like |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
84 server:port/chan/user (port, chan and user being optional)." |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
85 (let* ((parts (split-string link "/" t)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
86 (len (length parts))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
87 (when (or (< len 1) (> len 3)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
88 (error "Failed to parse link needed 1-3 parts, got %d." len)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
89 (setcar parts (split-string (car parts) ":" t)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
90 parts)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
91 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
92 ;;;###autoload |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
93 (defun org-irc-store-link () |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
94 "Dispatch to the appropreate function to store a link to |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
95 something IRC related" |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
96 (cond |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
97 ((eq major-mode 'erc-mode) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
98 (org-irc-erc-store-link)))) |
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 (defun org-irc-elipsify-description (string &optional after) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
101 "Strip starting and ending whitespace and replace any chars |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
102 that appear after the value in `after' with '...'" |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
103 (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
|
104 (replace-map (list (cons "^[ \t]*" "") |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
105 (cons "[ \t]*$" "") |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
106 (cons (concat "^\\(.\\{" after |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
107 "\\}\\).*") "\\1...")))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
108 (mapc (lambda (x) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
109 (when (string-match (car x) string) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
110 (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
|
111 replace-map) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
112 string)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
113 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
114 ;; ERC specific functions |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
115 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
116 (defun 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
|
117 "Find the most suitable line to link to from the erc logs. If |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
118 the user is on the erc-prompt then search backward for the first |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
119 non-blank line, otherwise return the current line. The result is |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
120 a cons of the filename and search string." |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
121 (erc-save-buffer-in-logs) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
122 (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
|
123 (goto-char (point-max)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
124 (list |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
125 (abbreviate-file-name buffer-file-name) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
126 ;; can we get a '::' part? |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
127 (if (string= erc-line (erc-prompt)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
128 (progn |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
129 (goto-char (point-at-bol)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
130 (when (search-backward-regexp "^[^ ]" nil t) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
131 (buffer-substring-no-properties (point-at-bol) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
132 (point-at-eol)))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
133 (when (search-backward erc-line nil t) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
134 (buffer-substring-no-properties (point-at-bol) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
135 (point-at-eol))))))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
136 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
137 (defun org-irc-erc-store-link () |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
138 "Depending on the variable `org-irc-link-to-logs' store either |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
139 a link to the log file for the current session or an irc: link to |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
140 the session itself." |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
141 (if org-irc-link-to-logs |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
142 (let* ((erc-line (buffer-substring-no-properties |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
143 (point-at-bol) (point-at-eol))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
144 (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
|
145 (if (erc-logging-enabled nil) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
146 (progn |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
147 (org-store-link-props |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
148 :type "file" |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
149 :description (concat "'" (org-irc-elipsify-description |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
150 (cadr parsed-line) 20) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
151 "' from an IRC conversation") |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
152 :link (concat "file:" (car parsed-line) "::" |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
153 (cadr parsed-line))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
154 t) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
155 (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
|
156 (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
|
157 (link (org-irc-parse-link link-text))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
158 (if link-text |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
159 (progn |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
160 (org-store-link-props |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
161 :type "irc" |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
162 :link (org-make-link "irc:/" link-text) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
163 :description (concat "irc session '" link-text "'") |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
164 :server (car (car link)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
165 :port (or (cadr (pop link)) erc-default-port) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
166 :nick (pop link)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
167 t) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
168 (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
|
169 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
170 (defun org-irc-get-erc-link () |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
171 "Return an org compatible irc:/ link from an ERC buffer" |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
172 (let ((link (concat erc-server-announced-name ":" |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
173 (number-to-string erc-session-port)))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
174 (concat link "/" |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
175 (if (and (erc-default-target) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
176 (erc-channel-p (erc-default-target)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
177 (car (get-text-property (point) 'erc-data))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
178 ;; we can get a nick |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
179 (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
|
180 (concat (erc-default-target) "/" nick)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
181 (erc-default-target))))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
182 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
183 (defun org-irc-visit-erc (link) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
184 "Visit an ERC buffer based on criteria from the followed link" |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
185 (let* ((server (car (car link))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
186 (port (or (cadr (pop link)) erc-default-port)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
187 (server-buffer) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
188 (buffer-list |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
189 (erc-buffer-filter |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
190 (lambda nil |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
191 (let ((tmp-server-buf (erc-server-buffer))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
192 (and tmp-server-buf |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
193 (with-current-buffer tmp-server-buf |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
194 (and |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
195 (string= erc-session-port port) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
196 (string= erc-server-announced-name server) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
197 (setq server-buffer tmp-server-buf))))))))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
198 (if buffer-list |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
199 (let ((chan-name (pop link))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
200 ;; 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
|
201 (if chan-name |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
202 (let ((chan-buf (catch 'found |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
203 (dolist (x buffer-list) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
204 (if (string= (buffer-name x) chan-name) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
205 (throw 'found x)))))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
206 (if chan-buf |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
207 (progn |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
208 (switch-to-buffer chan-buf) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
209 ;; 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
|
210 ;; then start a chat with them |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
211 (let ((nick (pop link))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
212 (when nick |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
213 (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
|
214 (progn |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
215 (goto-char (point-max)) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
216 (insert (concat nick ": "))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
217 (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
|
218 (progn |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
219 (switch-to-buffer server-buffer) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
220 (erc-cmd-JOIN chan-name)))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
221 (switch-to-buffer server-buffer))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
222 ;; no server match, make new connection |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
223 (erc-select :server server :port port)))) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
224 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
225 (provide 'org-irc) |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
226 |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
227 ;; arch-tag: 018d7dda-53b8-4a35-ba92-6670939e525a |
dda2c82177dc
Move org files to their own directory
Carsten Dominik <dominik@science.uva.nl>
parents:
diff
changeset
|
228 ;;; org-irc.el ends here |