unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#5135: [PATCH] Option to sort NAMES listing
@ 2009-12-06 17:16 Deniz Dogan
  2010-04-11  0:02 ` Chong Yidong
  0 siblings, 1 reply; 2+ messages in thread
From: Deniz Dogan @ 2009-12-06 17:16 UTC (permalink / raw)
  To: submit

[-- Attachment #1: Type: text/plain, Size: 1011 bytes --]

Package: emacs,rcirc
Tags: patch
Version: 22.1
Severity: wishlist

This patch adds the user option to sort nickname listings in the way
that many other IRC clients sort them.

Details:
* Added rcirc-nickname<, a function which acts like string< but for
IRC nicknames, making @ less than + and comparing case-insensitively.
* Added rcirc-sort-nicknames-join, a function which takes a string of
IRC nicknames and a separator, sorts the nicknames and returns the
result.
* Added rcirc-sort-nicknames, a customizable variable which when
non-nil will make rcirc sort any NAMES responses. nil by default.
* Changed rcirc-handler-366 (RPL_ENDOFNAMES) to respect rcirc-sort-nicknames.

Notes:
Sorting of half-ops has not been tested, since this is a rarely used
feature of IRC. For what it's worth, half-op nicknames are prefixed
with %. Sorting of voiced users (+) works as intended by default, so
the only special case is @ < +. If someone implements support for
half-ops it should be @ < % < + < *.

-- 
Deniz Dogan

[-- Attachment #2: rcirc-sort-nicknames.diff --]
[-- Type: application/octet-stream, Size: 2263 bytes --]

--- rcirc.bak.el	2009-12-06 16:17:24.650903900 +0100
+++ rcirc.el	2009-12-06 18:00:43.353485000 +0100
@@ -274,6 +274,11 @@
   :type 'hook
   :group 'rcirc)
 
+(defcustom rcirc-sort-nicknames nil
+  "If non-nil, sorts nickname listings."
+  :type 'boolean
+  :group 'rcirc)
+
 (defcustom rcirc-always-use-server-buffer-flag nil
   "Non-nil means messages without a channel target will go to the server buffer."
   :type 'boolean
@@ -1606,6 +1611,38 @@
 	    (delete nick rcirc-ignore-list-automatic)
 	    rcirc-ignore-list
 	    (delete nick rcirc-ignore-list))))
+
+(defun rcirc-nickname< (s1 s2)
+  "Compares two IRC nicknames.  Operator nicknames (@) are
+considered less than voiced nicknames (+).  Any other nicknames
+are greater than voiced nicknames.
+
+Returns t if S1 is less than S2, otherwise nil.
+
+The comparison is case-insensitive."
+  (setq s1 (downcase s1)
+        s2 (downcase s2))
+  (let* ((s1-op (eq ?@ (string-to-char s1)))
+         (s2-op (eq ?@ (string-to-char s2))))
+    (if s1-op
+        (if s2-op
+            (string< (substring s1 1) (substring s2 1))
+          t)
+      (if s2-op
+          nil
+        (string< s1 s2)))))
+
+(defun rcirc-sort-nicknames-join (input sep)
+  "Takes a string of nicknames and returns the string with the
+nicknames sorted.
+
+INPUT is a string containing nicknames separated by SEP.
+
+This function is non-destructive, sorting a copy of the input."
+  (let ((parts (split-string input sep t))
+        copy)
+    (setq copy (sort parts 'rcirc-nickname<))
+    (mapconcat 'identity copy sep)))
 \f
 ;;; activity tracking
 (defvar rcirc-track-minor-mode-map (make-sparse-keymap)
@@ -2512,7 +2549,10 @@
          (buffer (rcirc-get-temp-buffer-create process channel)))
     (with-current-buffer buffer
       (rcirc-print process sender "NAMES" channel
-                   (buffer-substring (point-min) (point-max))))
+                   (let ((content (buffer-substring (point-min) (point-max))))
+                     (if rcirc-sort-nicknames
+                         (rcirc-sort-nicknames-join content " ")
+                       content))))
     (kill-buffer buffer)))
 
 (defun rcirc-handler-433 (process sender args text)

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

* bug#5135: [PATCH] Option to sort NAMES listing
  2009-12-06 17:16 bug#5135: [PATCH] Option to sort NAMES listing Deniz Dogan
@ 2010-04-11  0:02 ` Chong Yidong
  0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2010-04-11  0:02 UTC (permalink / raw)
  To: Ryan Yeske; +Cc: 5135, Deniz Dogan

Hi Ryan,

Could you review the patch to rcirc at

  http://debbugs.gnu.org/cgi/bugreport.cgi?bug=5135

?  Thanks.






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

end of thread, other threads:[~2010-04-11  0:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-06 17:16 bug#5135: [PATCH] Option to sort NAMES listing Deniz Dogan
2010-04-11  0:02 ` Chong Yidong

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).