]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-irc.el
Update copyright year to 2015
[gnu-emacs] / lisp / org / org-irc.el
index fba274156db35753e22136a80cf7e61fe639b287..62f3d9596c56fac1ec98c3f02b18a40d9f8ea7a9 100644 (file)
@@ -1,10 +1,9 @@
 ;;; org-irc.el --- Store links to IRC sessions
 ;;
-;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2008-2015 Free Software Foundation, Inc.
 ;;
 ;; Author: Philip Jackson <emacs@shellarchive.co.uk>
 ;; Keywords: erc, irc, link, org
-;; Version: 7.4
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -60,6 +59,8 @@
 (declare-function erc-server-buffer "erc" ())
 (declare-function erc-get-server-nickname-list "erc" ())
 (declare-function erc-cmd-JOIN "erc" (channel &optional key))
+(declare-function org-pop-to-buffer-same-window
+                 "org-compat" (&optional buffer-or-name norecord label))
 
 (defvar org-irc-client 'erc
   "The IRC client to act on.")
   "Parse LINK and dispatch to the correct function based on the client found."
   (let ((link (org-irc-parse-link link)))
     (cond
-      ((eq org-irc-client 'erc)
-       (org-irc-visit-erc link))
-      (t
-       (error "erc only known client")))))
+     ((eq org-irc-client 'erc)
+      (org-irc-visit-erc link))
+     (t
+      (error "ERC only known client")))))
 
 (defun org-irc-parse-link (link)
   "Parse an IRC LINK and return the attributes found.
@@ -101,10 +102,10 @@ attributes that are found."
 (defun org-irc-store-link ()
   "Dispatch to the appropriate function to store a link to an IRC session."
   (cond
-    ((eq major-mode 'erc-mode)
-     (org-irc-erc-store-link))))
+   ((eq major-mode 'erc-mode)
+    (org-irc-erc-store-link))))
 
-(defun org-irc-elipsify-description (string &optional after)
+(defun org-irc-ellipsify-description (string &optional after)
   "Remove unnecessary white space from STRING and add ellipses if necessary.
 Strip starting and ending white space from STRING and replace any
 chars that the value AFTER with '...'"
@@ -139,9 +140,9 @@ result is a cons of the filename and search string."
           (when (search-backward-regexp "^[^   ]" nil t)
             (buffer-substring-no-properties (point-at-bol)
                                             (point-at-eol))))
-        (when (search-backward erc-line nil t)
-          (buffer-substring-no-properties (point-at-bol)
-                                          (point-at-eol)))))))
+       (when (search-backward erc-line nil t)
+        (buffer-substring-no-properties (point-at-bol)
+                                        (point-at-eol)))))))
 
 (defun org-irc-erc-store-link ()
   "Store a link to the IRC log file or the session itself.
@@ -157,33 +158,33 @@ the session itself."
            (progn
              (org-store-link-props
               :type "file"
-              :description (concat "'" (org-irc-elipsify-description
+              :description (concat "'" (org-irc-ellipsify-description
                                         (cadr parsed-line) 20)
                                    "' from an IRC conversation")
               :link (concat "file:" (car parsed-line) "::"
                             (cadr parsed-line)))
              t)
-           (error "This ERC session is not being logged")))
-      (let* ((link-text (org-irc-get-erc-link))
-            (link (org-irc-parse-link link-text)))
-       (if link-text
-           (progn
-             (org-store-link-props
-              :type "irc"
-              :link (org-make-link "irc:/" link-text)
-              :description (concat "irc session '" link-text "'")
-              :server (car (car link))
-              :port (or (string-to-number (cadr (pop link))) erc-default-port)
-              :nick (pop link))
-             t)
-           (error "Failed to create ('irc:/' style) ERC link")))))
+         (error "This ERC session is not being logged")))
+    (let* ((link-text (org-irc-get-erc-link))
+          (link (org-irc-parse-link link-text)))
+      (if link-text
+         (progn
+           (org-store-link-props
+            :type "irc"
+            :link (concat "irc:/" link-text)
+            :description (concat "irc session '" link-text "'")
+            :server (car (car link))
+            :port (or (string-to-number (cadr (pop link))) erc-default-port)
+            :nick (pop link))
+           t)
+       (error "Failed to create ('irc:/' style) ERC link")))))
 
 (defun org-irc-get-erc-link ()
   "Return an org compatible irc:/ link from an ERC buffer."
   (let* ((session-port (if (numberp erc-session-port)
                           (number-to-string erc-session-port)
-                          erc-session-port))
-         (link (concat erc-session-server ":" session-port)))
+                        erc-session-port))
+        (link (concat erc-session-server ":" session-port)))
     (concat link "/"
            (if (and (erc-default-target)
                     (erc-channel-p (erc-default-target))
@@ -191,19 +192,19 @@ the session itself."
                ;; we can get a nick
                (let ((nick (car (get-text-property (point) 'erc-data))))
                  (concat (erc-default-target) "/" nick))
-               (erc-default-target)))))
+             (erc-default-target)))))
 
 (defun org-irc-get-current-erc-port ()
   "Return the current port as a number.
 Return the current port number or, if none is set, return the ERC
 default."
   (cond
-    ((stringp erc-session-port)
-     (string-to-number erc-session-port))
-    ((numberp erc-session-port)
-     erc-session-port)
-    (t
-     erc-default-port)))
+   ((stringp erc-session-port)
+    (string-to-number erc-session-port))
+   ((numberp erc-session-port)
+    erc-session-port)
+   (t
+    erc-default-port)))
 
 (defun org-irc-visit-erc (link)
   "Visit an ERC buffer based on criteria found in LINK."
@@ -232,7 +233,7 @@ default."
                                      (throw 'found x))))))
                (if chan-buf
                    (progn
-                     (switch-to-buffer chan-buf)
+                     (org-pop-to-buffer-same-window chan-buf)
                      ;; if we got a nick, and they're in the chan,
                      ;; then start a chat with them
                      (let ((nick (pop link)))
@@ -241,16 +242,18 @@ default."
                              (progn
                                (goto-char (point-max))
                                (insert (concat nick ": ")))
-                             (error "%s not found in %s" nick chan-name)))))
-                   (progn
-                     (switch-to-buffer server-buffer)
-                     (erc-cmd-JOIN chan-name))))
-             (switch-to-buffer server-buffer)))
-       ;; no server match, make new connection
-       (erc-select :server server :port port))))
+                           (error "%s not found in %s" nick chan-name)))))
+                 (progn
+                   (org-pop-to-buffer-same-window server-buffer)
+                   (erc-cmd-JOIN chan-name))))
+           (org-pop-to-buffer-same-window server-buffer)))
+      ;; no server match, make new connection
+      (erc-select :server server :port port))))
 
 (provide 'org-irc)
 
-;; arch-tag: 018d7dda-53b8-4a35-ba92-6670939e525a
+;; Local variables:
+;; generated-autoload-file: "org-loaddefs.el"
+;; End:
 
 ;;; org-irc.el ends here