* riece.el (riece-submit-bug-report): Query CTCP VERSION.
[riece] / lisp / riece.el
index aeaea19..be0e9c2 100644 (file)
 
 ;;; Code:
 
-(require 'riece-filter)
 (require 'riece-display)
 (require 'riece-server)
 (require 'riece-compat)
 (require 'riece-commands)
 (require 'riece-addon)
+(require 'riece-signal)
 
 (autoload 'derived-mode-class "derived")
 
@@ -67,7 +67,8 @@
   "Non nil if add-ons are already insinuated.")
 
 (defvar riece-select-keys
-  `("1" riece-command-switch-to-channel-by-number-1
+  `("#" riece-command-switch-to-channel-by-number
+    "1" riece-command-switch-to-channel-by-number-1
     "2" riece-command-switch-to-channel-by-number-2
     "3" riece-command-switch-to-channel-by-number-3
     "4" riece-command-switch-to-channel-by-number-4
@@ -151,7 +152,9 @@ If optional argument SAFE is nil, overwrite previous definitions."
     [backspace] scroll-down
     [return] scroll-up
     " " scroll-up
+    [home] beginning-of-buffer
     "$" end-of-buffer
+    [end] end-of-buffer
     "/" riece-command-raw
     ">" end-of-buffer
     "<" beginning-of-buffer
@@ -194,7 +197,9 @@ If optional argument SAFE is nil, overwrite previous definitions."
     [delete] riece-command-scroll-down
     [backspace] riece-command-scroll-down
     " " riece-command-scroll-up
+    [home] riece-command-beginning-of-buffer
     "$" riece-command-end-of-buffer
+    [end] riece-command-end-of-buffer
     ">" riece-command-next-channel
     "<" riece-command-previous-channel
     "\C-j" riece-command-next-channel
@@ -299,18 +304,29 @@ If optional argument CONFIRM is non-nil, ask which IRC server to connect."
     (riece-display-connect-signals)
     (riece-redisplay-buffers)
     (riece-open-server riece-server "")
-    (let ((server-list riece-startup-server-list))
-      (while server-list
-       (riece-command-open-server (car server-list))
-       (setq server-list (cdr server-list))))
-    (let ((pointer riece-addons))
-      (while pointer
-       (unless (get (car pointer) 'riece-addon-default-disabled)
-         (riece-enable-addon (car pointer) riece-debug))
-       (setq pointer (cdr pointer))))
-    (run-hooks 'riece-startup-hook)
-    (message "%s" (substitute-command-keys
-                  "Type \\[describe-mode] for help"))))
+    ;; If no server process is available, exit.
+    (if (null riece-server-process-alist)
+       (riece-exit)
+      (let ((server-list riece-startup-server-list))
+       (while server-list
+         (riece-command-open-server (car server-list))
+         (setq server-list (cdr server-list))))
+      (let ((channel-list riece-startup-channel-list)
+           server)
+       (while channel-list
+         (setq server (riece-identity-server
+                       (riece-parse-identity (car channel-list))))
+         (unless (riece-server-opened server)
+           (riece-command-open-server server))
+         (setq channel-list (cdr channel-list))))
+      (let ((pointer riece-addons))
+       (while pointer
+         (unless (get (car pointer) 'riece-addon-default-disabled)
+           (riece-enable-addon (car pointer) riece-debug))
+         (setq pointer (cdr pointer))))
+      (run-hooks 'riece-startup-hook)
+      (message "%s" (substitute-command-keys
+                    "Type \\[describe-mode] for help")))))
 
 (defun riece-shrink-buffer (buffer)
   (save-excursion
@@ -328,10 +344,6 @@ If optional argument CONFIRM is non-nil, ask which IRC server to connect."
        (delete-region start end)))))
 
 (defun riece-exit ()
-  (let ((pointer riece-addons))
-    (while pointer
-      (riece-disable-addon (car pointer) riece-debug)
-      (setq pointer (cdr pointer))))
   (if riece-save-variables-are-dirty
       (riece-save-variables-files))
   (while riece-buffer-list
@@ -341,6 +353,7 @@ If optional argument CONFIRM is non-nil, ask which IRC server to connect."
     (setq riece-buffer-list (cdr riece-buffer-list)))
   (if riece-shrink-buffer-idle-timer
       (riece-cancel-timer riece-shrink-buffer-idle-timer))
+  (riece-clear-signal-slots)
   (setq riece-server nil
        riece-current-channels nil
        riece-current-channel nil
@@ -351,6 +364,7 @@ If optional argument CONFIRM is non-nil, ask which IRC server to connect."
        riece-channel-list-indicator "No channel"
        riece-away-indicator "-"
        riece-operator-indicator "-"
+       riece-channel-status-indicator "-"
        riece-freeze-indicator "-")
   (delete-other-windows)
   (run-hooks 'riece-exit-hook))
@@ -364,8 +378,15 @@ For a list of the generic commands type \\[riece-command-generic] ? RET.
   (interactive)
   (kill-all-local-variables)
 
+  ;; Make `truncate-partial-width-windows' buffer local and set it to
+  ;; nil.  This causes `truncate-lines' to directly control line
+  ;; truncation.
+  (make-local-variable 'truncate-partial-width-windows)
+  (setq truncate-partial-width-windows nil)
+
   (setq riece-away-indicator "-"
        riece-operator-indicator "-"
+       riece-channel-status-indicator "-"
        major-mode 'riece-command-mode
        mode-name "Command"
        mode-line-buffer-identification
@@ -373,10 +394,12 @@ For a list of the generic commands type \\[riece-command-generic] ? RET.
         '("Riece: "
           riece-away-indicator
           riece-operator-indicator
+          riece-channel-status-indicator
           " "
           riece-user-indicator
           " "
-          riece-channel-indicator)))
+          riece-channel-indicator))
+       truncate-lines nil)
   (riece-simplify-mode-line-format)
   (use-local-map riece-command-mode-map)
 
@@ -389,7 +412,7 @@ For a list of the generic commands type \\[riece-command-generic] ? RET.
      "^[]{}'`"))
 
   (run-hooks 'riece-command-mode-hook))
-  
+
 (defun riece-dialogue-mode ()
   "Major mode for displaying the IRC dialogue.
 All normal editing commands are turned off.
@@ -398,9 +421,16 @@ Instead, these commands are available:
   (kill-all-local-variables)
   (make-local-variable 'riece-freeze)
   (make-local-variable 'riece-freeze-indicator)
+
+  ;; Make `truncate-partial-width-windows' buffer local and set it to
+  ;; nil.  This causes `truncate-lines' to directly control line truncation.
+  (make-local-variable 'truncate-partial-width-windows)
+  (setq truncate-partial-width-windows nil)
+
   (setq riece-freeze riece-default-freeze
        riece-away-indicator "-"
        riece-operator-indicator "-"
+       riece-channel-status-indicator "-"
        major-mode 'riece-dialogue-mode
        mode-name "Dialogue"
        mode-line-buffer-identification
@@ -409,8 +439,10 @@ Instead, these commands are available:
           riece-away-indicator
           riece-operator-indicator
           riece-freeze-indicator
+          riece-channel-status-indicator
           " "
           riece-channel-list-indicator " "))
+       truncate-lines nil
        buffer-read-only t)
   (riece-simplify-mode-line-format)
   (use-local-map riece-dialogue-mode-map)
@@ -430,12 +462,14 @@ Instead, these commands are available:
 All normal editing commands are turned off.
 Instead, these commands are available:
 \\{riece-channel-mode-map}"
+  (make-local-variable 'riece-channel-buffer-window-point)
   (setq mode-line-buffer-identification
        (riece-mode-line-buffer-identification
         '("Riece: "
           riece-away-indicator
           riece-operator-indicator
           riece-freeze-indicator
+          riece-channel-status-indicator
           " "
           riece-long-channel-indicator))))
 
@@ -444,8 +478,14 @@ Instead, these commands are available:
 All normal editing commands are turned off."
   (kill-all-local-variables)
   (buffer-disable-undo)
+
+  ;; Make `truncate-partial-width-windows' buffer local and set it to
+  ;; nil.  This causes `truncate-lines' to directly control line truncation.
+  (make-local-variable 'truncate-partial-width-windows)
+  (setq truncate-partial-width-windows nil)
+
   (setq major-mode 'riece-channel-list-mode
-        mode-name "Channels"
+       mode-name "Channels"
        mode-line-buffer-identification
        (riece-mode-line-buffer-identification '("Riece: "))
        truncate-lines t
@@ -463,8 +503,14 @@ Instead, these commands are available:
 \\{riece-user-list-mode-map}"
   (kill-all-local-variables)
   (buffer-disable-undo)
+
+  ;; Make `truncate-partial-width-windows' buffer local and set it to
+  ;; nil.  This causes `truncate-lines' to directly control line truncation.
+  (make-local-variable 'truncate-partial-width-windows)
+  (setq truncate-partial-width-windows nil)
+
   (setq major-mode 'riece-user-list-mode
-        mode-name "Users"
+       mode-name "Users"
        mode-line-buffer-identification
        (riece-mode-line-buffer-identification
         '("Riece: " riece-long-channel-indicator " "))
@@ -489,7 +535,95 @@ Instead, these commands are available:
                    (eq major-mode (nth 2 (car alist))))
          (funcall (nth 2 (car alist))))
        (setq alist (cdr alist))))))
-      
+
+(defun riece-submit-bug-report (&optional recent-messages recent-keys)
+  "Submit via mail a bug report on Riece."
+  ;; This strange form ensures that (recent-keys) is the value before
+  ;; the bug subject string is read.
+  (interactive (list (riece-recent-messages 20) (recent-keys)))
+  (message "Checking CTCP VERSION...")
+  (let ((pointer riece-server-process-alist)
+       nickname)
+    (while pointer
+      (if (and (riece-server-process-opened (cdr (car pointer)))
+              (setq nickname
+                    (with-current-buffer (process-buffer (cdr (car pointer)))
+                    riece-real-nickname)))
+         (process-send-string
+          (cdr (car pointer))
+          (format "PRIVMSG %s :\1VERSION\1\r\n" nickname)))
+      (setq pointer (cdr pointer))))
+  (sit-for 3)
+  (message "Checking CTCP VERSION...done")
+  (require 'reporter)
+  (let ((reporter-prompt-for-summary-p t))
+    (unless riece-debug
+      (error "Please turn on riece-debug and restart Riece."))
+    (reporter-submit-bug-report
+     "liece@unixuser.org"
+     (riece-version)
+     '(riece-debug)
+     nil
+     nil
+     "This bug report will be sent to the Riece Development Team,
+not to your local site managers!!
+
+Please write in Japanese or English, because the Riece maintainers do
+not have translators to read other languages for them.
+
+Please describe as succinctly as possible:
+\t- What happened.
+\t- What you thought should have happened.
+\t- Precisely what you were doing at the time.
+
+Also include a reliable recipe for triggering the bug, as well as
+any lisp back-traces that you may have.
+\(setq stack-trace-on-error t\), or \(setq debug-on-error t\) if you
+are familiar with the debugger, to get a lisp back-trace.")
+      (save-excursion
+       (goto-char (point-max))
+       (insert
+        "\nAdd-on state:\n"
+        "------------\n"
+        (save-window-excursion
+          (save-excursion
+            (riece-command-list-addons)
+            (search-forward "\n\n")
+            (buffer-substring (point-min) (point)))))
+       (insert "Recent messages from servers:\n"
+               "--------------------------")
+       (let ((pointer riece-server-process-alist))
+         (while pointer
+           (insert "\n- \"" (car (car pointer)) "\", \n"
+                   (format "%S" (if (equal (car (car pointer)) "")
+                                    riece-server
+                                  (cdr (assoc (car (car pointer))
+                                              riece-server-alist))))
+                   "\n"
+                   (if (riece-server-process-opened (cdr (car pointer)))
+                       (save-excursion
+                         (set-buffer (process-buffer (cdr (car pointer))))
+                         (goto-char (point-max))
+                         (beginning-of-line -60)
+                         (buffer-substring (point) (point-max)))
+                     "(closed server)"))
+           (setq pointer (cdr pointer))))
+       ;; Insert recent keystrokes.
+       (insert "\n\nRecent keystrokes:\n"
+               "-----------------\n\n")
+       (let ((before-keys (point)))
+       (insert (key-description recent-keys))
+       (save-restriction
+         (narrow-to-region before-keys (point))
+         (goto-char before-keys)
+         (while (progn (move-to-column 50) (not (eobp)))
+           (search-forward " " nil t)
+           (insert "\n"))))
+       ;; Insert recent minibuffer messages.
+       (insert "\n\nRecent messages (most recent first):\n"
+               "-----------------------------------\n"
+               recent-messages))))
+
 (provide 'riece)
 
 ;;; riece.el ends here