unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* PATCH: Add the ability to give rcirc servers an alias name
@ 2015-11-07 23:00 Dave Barker
  2015-11-08 17:45 ` Dave Barker
  0 siblings, 1 reply; 21+ messages in thread
From: Dave Barker @ 2015-11-07 23:00 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 1322 bytes --]

Hello all,

First time contributing to Emacs (or at least attempting to), sorry if I'm
doing this wrong somehow.

I wanted the ability to give rcirc servers an alias name, to be displayed
instead of the actual server name. The reason is that I use the ZNC IRC
bouncer to connect to multiple servers and this means, as far as rcirc is
concerned, that I have 4+ servers with the same server name - my ZNC
server's hostname. This breaks rcirc, it won't let you connect to the same
server twice, but even if it did things would quickly get confusing. (Up
until now I've had to add bogus entries in my hosts file to point each IRC
server's hostname to my ZNC server, but that's clearly quite a hack!)

So the attached patch adds an optional :server-alias keyword parameter
to rcirc-server-alist that allows you to specify a friendlier name for a
rcirc server. The name is then used when messages are displayed, and for
buffer naming purposes. If not specified the real server name is used
instead just like before. (For people who are used to GitHub, here's my
feature branch <https://github.com/kzar/emacs/tree/rcirc-server-alias>.)

It would be great to get some feedback on this, the patch is working great
for me but I'm inexperienced with elisp and this is the first time I've had
a look at the rcirc code.

Cheers, Dave.

[-- Attachment #1.2: Type: text/html, Size: 1513 bytes --]

[-- Attachment #2: 0001-Add-ability-to-give-rcirc-servers-an-alias-name.patch --]
[-- Type: text/x-patch, Size: 4607 bytes --]

From cb54e4d668577c2e7d0d53b8bd54c7dcfc87f403 Mon Sep 17 00:00:00 2001
From: Dave Barker <kzar@kzar.co.uk>
Date: Sat, 7 Nov 2015 22:32:51 +0000
Subject: [PATCH] Add ability to give rcirc servers an alias name

---
 lisp/net/rcirc.el | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index d58f3eb..a309a47 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -103,7 +103,12 @@ connected to automatically.
 `:encryption'
 
 VALUE must be `plain' (the default) for unencrypted connections, or `tls'
-for connections using SSL/TLS."
+for connections using SSL/TLS.
+
+`:server-alias'
+
+VALUE must be a string that will be used instead of the server name for
+display purposes. If absent, the real server name will be displayed instead."
   :type '(alist :key-type string
 		:value-type (plist :options
                                    ((:nick string)
@@ -113,7 +118,8 @@ for connections using SSL/TLS."
                                     (:full-name string)
                                     (:channels (repeat string))
                                     (:encryption (choice (const tls)
-                                                         (const plain))))))
+                                                         (const plain)))
+                                    (:server-alias string))))
   :group 'rcirc)
 
 (defcustom rcirc-default-port 6667
@@ -484,17 +490,20 @@ If ARG is non-nil, instead prompt for connection parameters."
 	      (channels (plist-get (cdr c) :channels))
               (password (plist-get (cdr c) :password))
               (encryption (plist-get (cdr c) :encryption))
+              (server-alias (plist-get (cdr c) :server-alias))
               contact)
 	  (when server
 	    (let (connected)
 	      (dolist (p (rcirc-process-list))
-		(when (string= server (process-name p))
+		(when (string= (or server-alias server) (process-name p))
 		  (setq connected p)))
 	      (if (not connected)
 		  (condition-case nil
 		      (rcirc-connect server port nick user-name
-				     full-name channels password encryption)
-		    (quit (message "Quit connecting to %s" server)))
+                                     full-name channels password encryption
+                                     server-alias)
+		    (quit (message "Quit connecting to %s"
+                                   (or server-alias server))))
 		(with-current-buffer (process-buffer connected)
                   (setq contact (process-contact
                                  (get-buffer-process (current-buffer)) :host))
@@ -528,9 +537,10 @@ If ARG is non-nil, instead prompt for connection parameters."
 
 ;;;###autoload
 (defun rcirc-connect (server &optional port nick user-name
-                             full-name startup-channels password encryption)
+                             full-name startup-channels password encryption
+                             server-alias)
   (save-excursion
-    (message "Connecting to %s..." server)
+    (message "Connecting to %s..." (or server-alias server))
     (let* ((inhibit-eol-conversion)
            (port-number (if port
 			    (if (stringp port)
@@ -542,7 +552,7 @@ If ARG is non-nil, instead prompt for connection parameters."
 	   (full-name (or full-name rcirc-default-full-name))
 	   (startup-channels startup-channels)
            (process (open-network-stream
-                     server nil server port-number
+                     (or server-alias server) nil server port-number
                      :type (or encryption 'plain))))
       ;; set up process
       (set-process-coding-system process 'raw-text 'raw-text)
@@ -557,7 +567,8 @@ If ARG is non-nil, instead prompt for connection parameters."
 			password encryption))
       (setq-local rcirc-process process)
       (setq-local rcirc-server server)
-      (setq-local rcirc-server-name server) ; Update when we get 001 response.
+      (setq-local rcirc-server-name
+                  (or server-alias server)) ; Update when we get 001 response.
       (setq-local rcirc-buffer-alist nil)
       (setq-local rcirc-nick-table (make-hash-table :test 'equal))
       (setq-local rcirc-nick nick)
@@ -584,7 +595,7 @@ If ARG is non-nil, instead prompt for connection parameters."
 	(setq rcirc-keepalive-timer
 	      (run-at-time 0 (/ rcirc-timeout-seconds 2) 'rcirc-keepalive)))
 
-      (message "Connecting to %s...done" server)
+      (message "Connecting to %s...done" (or server-alias server))
 
       ;; return process object
       process)))
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2016-01-31 14:05 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-07 23:00 PATCH: Add the ability to give rcirc servers an alias name Dave Barker
2015-11-08 17:45 ` Dave Barker
2015-11-08 19:22   ` Artur Malabarba
2015-11-08 18:52     ` Ryan Yeske
2015-11-08 19:01       ` Dave Barker
2015-11-18 11:20         ` Dave Barker
2015-12-13 18:23           ` Dave Barker
2015-12-16  6:16             ` Ryan Yeske
2015-12-16 12:29               ` Dave Barker
2015-12-17 18:40                 ` Ryan Yeske
2015-12-18 10:46                   ` Dave Barker
2015-12-18 13:34                     ` Artur Malabarba
2015-12-18 14:52                       ` Dave Barker
2016-01-03 23:11                         ` Artur Malabarba
2016-01-07 11:52                           ` Dave Barker
2016-01-07 16:12                             ` Eli Zaretskii
2016-01-07 19:23                               ` Artur Malabarba
2016-01-08  5:57                             ` Richard Stallman
2016-01-08 11:07                               ` Dave Barker
2016-01-09  3:23                                 ` Richard Stallman
2016-01-31 14:05                                   ` Dave Barker

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).