From 02be81743ac5dd75edad48186c8849074303e999 Mon Sep 17 00:00:00 2001 From: ueno Date: Mon, 13 Oct 2003 04:44:37 +0000 Subject: [PATCH] * riece-unread.el (riece-unread-after-display-message-function): Do nothing when message-target is already in riece-unread-channels; call riece-redisplay-buffers. (riece-unread-update-channel-list-buffer): Abolish. (riece-unread-after-switch-to-channel-function): Don't call riece-unread-update-channel-list-buffer. (riece-unread-format-channel-list-line): New function. (riece-unread-insinuate): Add riece-unread-format-channel-list-line to riece-format-channel-list-line; don't add riece-unread-update-channel-list-buffer to riece-update-buffer-functions. * riece-highlight.el (riece-channel-list-mark-current-channel): Abolish; merged into riece-update-channel-list-buffer. (riece-highlight-insinuate): Don't add riece-channel-list-mark-current-channel to riece-after-switch-to-channel-functions. * riece-display.el (riece-channel-list-changed): Abolish. (riece-update-channel-list-buffer): Always redisplay channel-list buffer. (riece-update-channel-list-indicator): Always redisplay channel-list indicator. (riece-format-channel-list-line): New function. (riece-update-buffers): Don't clear riece-channel-list-changed. (riece-join-channel): Don't set riece-channel-list-changed. (riece-part-channel): Ditto. --- lisp/ChangeLog | 31 ++++++++++++++ lisp/riece-button.el | 102 +++++++++++++++++++++++++++++++++++++++++++++++ lisp/riece-display.el | 86 ++++++++++++++++++++------------------- lisp/riece-highlight.el | 20 ---------- lisp/riece-unread.el | 46 ++++++++------------- 5 files changed, 193 insertions(+), 92 deletions(-) create mode 100644 lisp/riece-button.el diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 718ea81..d455de5 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,36 @@ 2003-10-13 Daiki Ueno + * riece-unread.el (riece-unread-after-display-message-function): + Do nothing when message-target is already in + riece-unread-channels; call riece-redisplay-buffers. + (riece-unread-update-channel-list-buffer): Abolish. + (riece-unread-after-switch-to-channel-function): Don't call + riece-unread-update-channel-list-buffer. + (riece-unread-format-channel-list-line): New function. + (riece-unread-insinuate): Add + riece-unread-format-channel-list-line to + riece-format-channel-list-line; don't add + riece-unread-update-channel-list-buffer to + riece-update-buffer-functions. + + * riece-highlight.el (riece-channel-list-mark-current-channel): + Abolish; merged into riece-update-channel-list-buffer. + (riece-highlight-insinuate): Don't add + riece-channel-list-mark-current-channel to + riece-after-switch-to-channel-functions. + + * riece-display.el (riece-channel-list-changed): Abolish. + (riece-update-channel-list-buffer): Always redisplay channel-list + buffer. + (riece-update-channel-list-indicator): Always redisplay + channel-list indicator. + (riece-format-channel-list-line): New function. + (riece-update-buffers): Don't clear riece-channel-list-changed. + (riece-join-channel): Don't set riece-channel-list-changed. + (riece-part-channel): Ditto. + +2003-10-13 Daiki Ueno + * riece-options.el (riece-addons): Add riece-button. * riece-display.el (riece-update-channel-list-buffer): Avoid to diff --git a/lisp/riece-button.el b/lisp/riece-button.el new file mode 100644 index 0000000..f65e7bf --- /dev/null +++ b/lisp/riece-button.el @@ -0,0 +1,102 @@ +;;; riece-button.el --- adding buttons in channel buffers +;; Copyright (C) 1998-2003 Daiki Ueno + +;; Author: Daiki Ueno +;; Created: 1998-09-28 +;; Keywords: IRC, riece + +;; This file is part of Riece. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; To use, add the following line to your ~/.riece/init.el: +;; (add-to-list 'riece-addons 'riece-button) + +;;; Code: + +(require 'riece-commands) +(require 'riece-identity) +(require 'riece-misc) +(require 'wid-edit) + +(defvar help-echo-owns-message) +(define-widget 'riece-channel-button 'push-button + "A channel button." + :action 'riece-channel-button-action + :help-echo + (lambda (widget/window &optional overlay pos) + ;; Needed to properly clear the message due to a bug in + ;; wid-edit (XEmacs only). + (if (boundp 'help-echo-owns-message) + (setq help-echo-owns-message t)) + (format "Switch to %s" + ;; XEmacs will get a single widget arg; Emacs 21 will get + ;; window, overlay, position. + (riece-format-identity + (if overlay + (with-current-buffer (overlay-buffer overlay) + (widget-value (widget-at (overlay-start overlay)))) + (widget-value widget/window)))))) + +(defun riece-channel-button-action (widget &optional event) + (let ((channel (widget-value widget))) + (if (riece-identity-member channel riece-current-channels) + (riece-command-switch-to-channel channel) + (message "%s" (substitute-command-keys + "Type \\[riece-command-join] to join the channel"))))) + +(defun riece-button-add-channel-buttons (start end length) + (save-excursion + (catch 'done + (while t + ;; Search for the beginning of the button region. + (unless (get-text-property start 'riece-identity) + (setq start (next-single-property-change start 'riece-identity + nil end))) + ;; Search for the end of the button region. + (let* ((identity (get-text-property start 'riece-identity)) + (button-end (next-single-property-change start 'riece-identity + nil end))) + (if (= button-end end) + (throw 'done nil) + (if (riece-channel-p (riece-identity-prefix identity)) + (widget-convert-button + 'riece-channel-button start button-end identity)) + (setq start button-end))))))) + +(defun riece-button-update-channel-list-buffer () + (if riece-channel-list-buffer-mode + (save-excursion + (set-buffer riece-channel-list-buffer) + (let ((inhibit-read-only t) + buffer-read-only) + (riece-button-add-channel-buttons (point-min) (point-max) nil))))) + +(defun riece-button-requires () + '(riece-highlight)) + +(defun riece-button-insinuate () + (add-hook 'riece-channel-list-mode-hook + (lambda () + (set-keymap-parent riece-channel-list-mode-map widget-keymap) + (add-hook 'riece-update-buffer-functions + 'riece-button-update-channel-list-buffer t)))) + +(provide 'riece-button) + +;;; riece-button.el ends here diff --git a/lisp/riece-display.el b/lisp/riece-display.el index d29f785..288b46c 100644 --- a/lisp/riece-display.el +++ b/lisp/riece-display.el @@ -37,8 +37,6 @@ riece-update-short-channel-indicator riece-update-channel-list-indicator)) -(defvar riece-channel-list-changed nil) - (defun riece-update-user-list-buffer () (save-excursion (set-buffer riece-user-list-buffer) @@ -69,22 +67,30 @@ (setq users (cdr users)))))))) (defun riece-update-channel-list-buffer () - (if riece-channel-list-changed - (save-excursion - (set-buffer riece-channel-list-buffer) - (let ((inhibit-read-only t) - buffer-read-only - (index 1) - (channels riece-current-channels)) - (erase-buffer) - (while channels - (if (car channels) - (let ((point (point))) - (insert (format "%2d: " index) - (riece-format-identity (car channels)) - "\n"))) - (setq index (1+ index) - channels (cdr channels))))))) + (save-excursion + (set-buffer riece-channel-list-buffer) + (let ((inhibit-read-only t) + buffer-read-only + (index 1) + (channels riece-current-channels)) + (erase-buffer) + (while channels + (if (car channels) + (let ((point (point))) + (insert (riece-format-channel-list-line + index (car channels))))) + (setq index (1+ index) + channels (cdr channels)))))) + +(defun riece-format-channel-list-line (index channel) + (or (run-hook-with-args-until-success + 'riece-format-channel-list-line-functions index channel) + (concat (format "%2d:%c" index + (if (riece-identity-equal channel riece-current-channel) + ?* + ? )) + (riece-format-identity channel) + "\n"))) (defun riece-update-channel-indicator () (setq riece-channel-indicator @@ -105,25 +111,24 @@ "None"))) (defun riece-update-channel-list-indicator () - (if riece-channel-list-changed - (if (and riece-current-channels - ;; There is at least one channel. - (delq nil (copy-sequence riece-current-channels))) - (let ((index 1)) - (setq riece-channel-list-indicator - (mapconcat - #'identity - (delq nil - (mapcar - (lambda (channel) - (prog1 - (if channel - (format "%d:%s" index - (riece-format-identity channel))) - (setq index (1+ index)))) - riece-current-channels)) - ","))) - (setq riece-channel-list-indicator "No channel")))) + (if (and riece-current-channels + ;; There is at least one channel. + (delq nil (copy-sequence riece-current-channels))) + (let ((index 1)) + (setq riece-channel-list-indicator + (mapconcat + #'identity + (delq nil + (mapcar + (lambda (channel) + (prog1 + (if channel + (format "%d:%s" index + (riece-format-identity channel))) + (setq index (1+ index)))) + riece-current-channels)) + ","))) + (setq riece-channel-list-indicator "No channel"))) (defun riece-update-status-indicators () (if riece-current-channel @@ -156,7 +161,6 @@ (setq riece-channel-buffer (get-buffer (riece-channel-buffer-name riece-current-channel)))) (run-hooks 'riece-update-buffer-functions) - (setq riece-channel-list-changed nil) (force-mode-line-update t)) (defun riece-channel-buffer-name (identity) @@ -198,8 +202,7 @@ (if channel (riece-parse-identity channel))) riece-default-channel-binding))) - (riece-channel-buffer-create identity) - (setq riece-channel-list-changed t))) + (riece-channel-buffer-create identity))) (defun riece-switch-to-nearest-channel (pointer) (let ((start riece-current-channels) @@ -224,8 +227,7 @@ (if pointer (setcar pointer nil)) (if (riece-identity-equal identity riece-current-channel) - (riece-switch-to-nearest-channel pointer)) - (setq riece-channel-list-changed t))) + (riece-switch-to-nearest-channel pointer)))) (defun riece-redisplay-buffers (&optional force) (riece-update-buffers) diff --git a/lisp/riece-highlight.el b/lisp/riece-highlight.el index addb260..a56b4fa 100644 --- a/lisp/riece-highlight.el +++ b/lisp/riece-highlight.el @@ -221,24 +221,6 @@ (if (looking-at riece-prefix-regexp) (put-text-property (match-beginning 1) (match-end 1) 'invisible t)))) -(defun riece-channel-list-mark-current-channel (last) - (if (and riece-channel-list-buffer-mode - riece-current-channel) - (save-excursion - (set-buffer riece-channel-list-buffer) - (let ((inhibit-read-only t) - buffer-read-only) - (goto-char (point-min)) - (if (re-search-forward "^\\( ?[0-9]+:\\)\\*" nil t) - (replace-match "\\1 ")) - (goto-char (point-min)) - (if (re-search-forward - (concat - "^\\( ?[0-9]+:\\).\\(" - (regexp-quote (riece-format-identity riece-current-channel)) - "\\)$") nil t) - (replace-match "\\1*\\2")))))) - (defun riece-channel-list-turn-on-font-lock () (make-local-variable 'font-lock-defaults) (setq font-lock-defaults '(riece-channel-list-font-lock-keywords t)) @@ -262,8 +244,6 @@ 'riece-dialogue-schedule-turn-on-font-lock) (put 'riece-channel-list-mode 'font-lock-defaults '(riece-channel-list-font-lock-keywords t)) - (add-hook 'riece-after-switch-to-channel-functions - 'riece-channel-list-mark-current-channel) (add-hook 'riece-after-load-startup-hook 'riece-channel-list-schedule-turn-on-font-lock)) diff --git a/lisp/riece-unread.el b/lisp/riece-unread.el index 9e89695..47c998a 100644 --- a/lisp/riece-unread.el +++ b/lisp/riece-unread.el @@ -61,37 +61,25 @@ (defun riece-unread-after-display-message-function (message) (unless (or (riece-message-own-p message) - (equal (riece-message-target message) riece-current-channel)) + (riece-identity-equal (riece-message-target message) + riece-current-channel) + (riece-identity-member (riece-message-target message) + riece-unread-channels)) (setq riece-unread-channels - (cons (riece-message-target message) - (delete (riece-message-target message) riece-unread-channels))) - (riece-unread-update-channel-list-buffer))) + (cons (riece-message-target message) riece-unread-channels)) + (riece-redisplay-buffers))) (defun riece-unread-after-switch-to-channel-function (last) (setq riece-unread-channels (delete riece-current-channel - riece-unread-channels)) - (riece-unread-update-channel-list-buffer)) - -(defun riece-unread-update-channel-list-buffer () - (if riece-channel-list-buffer-mode - (save-excursion - (set-buffer riece-channel-list-buffer) - (let ((inhibit-read-only t) - buffer-read-only) - (goto-char (point-min)) - (while (not (eobp)) - (if (looking-at "\\( ?[0-9]+:\\)\\(.\\)") - (let ((channel (get-text-property (match-end 0) - 'riece-identity))) - (replace-match - (concat "\\1" - (if (riece-identity-member channel - riece-unread-channels) - "!" - "\\2"))))) - (forward-line)))))) - + riece-unread-channels))) + +(defun riece-unread-format-channel-list-line (index channel) + (if (riece-identity-member channel riece-unread-channels) + (concat (format "%2d:!" index) + (riece-format-identity channel) + "\n"))) + (defun riece-unread-switch-to-channel () (interactive) (if (car riece-unread-channels) @@ -118,10 +106,8 @@ 'riece-unread-after-display-message-function) (add-hook 'riece-after-switch-to-channel-functions 'riece-unread-after-switch-to-channel-function) - (add-hook 'riece-channel-list-mode-hook - (lambda () - (add-hook 'riece-update-buffer-functions - 'riece-unread-update-channel-list-buffer t))) + (add-hook 'riece-format-channel-list-line-functions + 'riece-unread-format-channel-list-line) (define-key riece-command-mode-map "\C-c\C-u" 'riece-unread-switch-to-channel) (define-key riece-dialogue-mode-map -- 1.7.10.4