[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Erc-commit] [commit][emacs22] erc-track: Allow switching to buffer with
From: |
mwolson |
Subject: |
[Erc-commit] [commit][emacs22] erc-track: Allow switching to buffer with most important message type first |
Date: |
Sun, 14 Oct 2007 00:49:09 -0400 |
commit 2c7ea5ca18101c33f512dc15ba334fe214a5cd74
Author: Michael W. Olson <address@hidden>
Date: Wed Aug 15 23:26:45 2007 -0400
erc-track: Allow switching to buffer with most important message type first
* erc-track.el (erc-track-switch-direction): Add 'importance option.
(erc-modified-channels-display): If erc-track-switch-direction is
'importance, call erc-track-sort-by-importance.
(erc-track-face-priority): New function that returns a number
indicating the position of a face in erc-track-faces-priority-list.
(erc-track-sort-by-importance): New function that sorts
erc-modified-channels-list according to erc-track-face-priority.
(erc-track-get-active-buffer): Make 'oldest a rough opposite of
'importance.
diff --git a/ChangeLog b/ChangeLog
index 87426c9..11c77a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,16 @@
* erc-track.el (erc-track-list-changed-hook): Turn this into a
customizable option.
+ (erc-track-switch-direction): Add 'importance option.
+ (erc-modified-channels-display): If erc-track-switch-direction is
+ 'importance, call erc-track-sort-by-importance.
+ (erc-track-face-priority): New function that returns a number
+ indicating the position of a face in
+ erc-track-faces-priority-list.
+ (erc-track-sort-by-importance): New function that sorts
+ erc-modified-channels-list according to erc-track-face-priority.
+ (erc-track-get-active-buffer): Make 'oldest a rough opposite of
+ 'importance.
2007-08-14 Jeremy Maitin-Shepard <address@hidden>
diff --git a/erc-track.el b/erc-track.el
index 8c1d3e6..5865257 100644
--- a/erc-track.el
+++ b/erc-track.el
@@ -281,12 +281,14 @@ when there are no more active channels."
(defcustom erc-track-switch-direction 'oldest
"Direction `erc-track-switch-buffer' should switch.
+ importance - find buffer with the most important message
oldest - find oldest active buffer
newest - find newest active buffer
leastactive - find buffer with least unseen messages
mostactive - find buffer with most unseen messages."
:group 'erc-track
- :type '(choice (const oldest)
+ :type '(choice (const importance)
+ (const oldest)
(const newest)
(const leastactive)
(const mostactive)))
@@ -758,10 +760,11 @@ If FACES are provided, color STRING with them."
"Set `erc-modified-channels-object'
according to `erc-modified-channels-alist'.
Use `erc-make-mode-line-buffer-name' to create buttons."
- (if (or
- (eq 'mostactive erc-track-switch-direction)
- (eq 'leastactive erc-track-switch-direction))
- (erc-track-sort-by-activest))
+ (cond ((or (eq 'mostactive erc-track-switch-direction)
+ (eq 'leastactive erc-track-switch-direction))
+ (erc-track-sort-by-activest))
+ ((eq 'importance erc-track-switch-direction)
+ (erc-track-sort-by-importance)))
(run-hooks 'erc-track-list-changed-hook)
(unless (eq erc-track-position-in-mode-line nil)
(if (null erc-modified-channels-alist)
@@ -917,6 +920,29 @@ That means the number of unseen messages in a channel."
(sort erc-modified-channels-alist
(lambda (a b) (> (nth 1 a) (nth 1 b))))))
+(defun erc-track-face-priority (face)
+ "Return a number indicating the priority of FACE in
+`erc-track-faces-priority-list'. Lower number means higher
+priority.
+
+If face is not in `erc-track-faces-priority-list', it will have a
+higher number than any other face in that list."
+ (let ((count 0))
+ (catch 'done
+ (dolist (item erc-track-faces-priority-list)
+ (if (eq item face)
+ (throw 'done t)
+ (setq count (1+ count)))))
+ count))
+
+(defun erc-track-sort-by-importance ()
+ "Sort erc-modified-channels-alist by importance.
+That means the position of the face in `erc-track-faces-priority-list'."
+ (setq erc-modified-channels-alist
+ (sort erc-modified-channels-alist
+ (lambda (a b) (< (erc-track-face-priority (cddr a))
+ (erc-track-face-priority (cddr b)))))))
+
(defun erc-track-get-active-buffer (arg)
"Return the buffer name of ARG in `erc-modified-channels-alist'.
Negative arguments index in the opposite direction. This direction is
@@ -928,7 +954,8 @@ relative to `erc-track-switch-direction'"
(oldest 'newest)
(newest 'oldest)
(mostactive 'leastactive)
- (leastactive 'mostactive)))
+ (leastactive 'mostactive)
+ (importance 'oldest)))
(setq arg (- arg)))
(setq offset (case dir
((oldest leastactive)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Erc-commit] [commit][emacs22] erc-track: Allow switching to buffer with most important message type first,
mwolson <=