* liece.el (liece-refresh-buffer-window): Force to display a last
[elisp/liece.git] / lisp / liece.el
index a9c3e05..e0711ef 100644 (file)
     "Mapping from keywords to default values.
 All keywords that can be used must be listed here."))
 
     "Mapping from keywords to default values.
 All keywords that can be used must be listed here."))
 
-(defadvice save-buffers-kill-emacs
-  (before liece-save-buffers-kill-emacs activate)
-  "Prompt user to quit IRC explicitly."
-  (run-hooks 'liece-before-kill-emacs-hook) )
-
-(add-hook 'liece-before-kill-emacs-hook 'liece-command-quit)
+(add-hook 'kill-emacs-hook 'liece-command-quit)
 
 (defvar liece-tmp-server-name nil "Temporaly server name.")
 (defvar liece-buffer-last-check-time nil)
 
 (defvar liece-tmp-server-name nil "Temporaly server name.")
 (defvar liece-buffer-last-check-time nil)
@@ -202,7 +197,6 @@ If optional argument SAFE is nil, overwrite previous definitions."
     "/" liece-command-generic
     ">" end-of-buffer
     "<" beginning-of-buffer
     "/" liece-command-generic
     ">" end-of-buffer
     "<" beginning-of-buffer
-    "!" liece-command-exec
     "|" liece-command-show-last-kill
     "a" liece-command-away
     "b" liece-command-submit-bug-report
     "|" liece-command-show-last-kill
     "a" liece-command-away
     "b" liece-command-submit-bug-report
@@ -230,8 +224,6 @@ If optional argument SAFE is nil, overwrite previous definitions."
     "t" liece-command-topic
     "T" liece-command-timestamp
     "\C-t" liece-command-find-timestamp
     "t" liece-command-topic
     "T" liece-command-timestamp
     "\C-t" liece-command-find-timestamp
-    "u" liece-command-lusers
-    "U" liece-command-userhost
     "v" liece-command-browse-url
     "w" liece-command-who)
 
     "v" liece-command-browse-url
     "w" liece-command-who)
 
@@ -266,11 +258,7 @@ If optional argument SAFE is nil, overwrite previous definitions."
     "\r" liece-command-enter-message
     [tab] liece-command-complete
     [(meta control c) >] liece-command-push
     "\r" liece-command-enter-message
     [tab] liece-command-complete
     [(meta control c) >] liece-command-push
-    [(meta control c) <] liece-command-pop
-    [(meta control c) o] liece-command-mode+o
-    [(meta control c) O] liece-command-mode-o
-    [(meta control c) v] liece-command-mode+v
-    [(meta control c) V] liece-command-mode-v)
+    [(meta control c) <] liece-command-pop)
 
   (liece-define-keys (liece-command-map "\C-c" liece-command-mode-map)
     "\177" liece-command-scroll-down
 
   (liece-define-keys (liece-command-map "\C-c" liece-command-mode-map)
     "\177" liece-command-scroll-down
@@ -281,8 +269,6 @@ If optional argument SAFE is nil, overwrite previous definitions."
     ">" liece-command-next-channel
     "<" liece-command-previous-channel
     "a" liece-command-away
     ">" liece-command-next-channel
     "<" liece-command-previous-channel
     "a" liece-command-away
-    "c" liece-command-inline
-    "\C-a" liece-command-previous-channel
     "\C-f" liece-command-freeze
     "\C-j" liece-command-next-channel
     "\C-n" liece-command-names
     "\C-f" liece-command-freeze
     "\C-j" liece-command-next-channel
     "\C-n" liece-command-names
@@ -291,7 +277,7 @@ If optional argument SAFE is nil, overwrite previous definitions."
     "L" liece-command-load-vars
     "M" liece-command-own-freeze
     "\C-m" liece-command-modec
     "L" liece-command-load-vars
     "M" liece-command-own-freeze
     "\C-m" liece-command-modec
-    "o" liece-command-mode+o
+    "o" liece-command-set-operators
     "O" liece-command-toggle-nick-buffer-mode
     "\C-o" liece-command-toggle-channel-buffer-mode
     "\C-p" liece-command-part
     "O" liece-command-toggle-nick-buffer-mode
     "\C-o" liece-command-toggle-channel-buffer-mode
     "\C-p" liece-command-part
@@ -299,16 +285,14 @@ If optional argument SAFE is nil, overwrite previous definitions."
     "\C-r" mule-caesar-region
     "s" liece-command-set-window-style
     "S" liece-command-save-vars
     "\C-r" mule-caesar-region
     "s" liece-command-set-window-style
     "S" liece-command-save-vars
-    "v" liece-command-mode+v
+    "v" liece-command-set-voices
     "\C-v" liece-command-browse-url
     "\C-y" liece-command-yank-send)
   (set-keymap-parent liece-command-map liece-dialogue-mode-map)
 
   (liece-define-keys liece-nick-mode-map
     "\C-v" liece-command-browse-url
     "\C-y" liece-command-yank-send)
   (set-keymap-parent liece-command-map liece-dialogue-mode-map)
 
   (liece-define-keys liece-nick-mode-map
-    "o" liece-command-mode+o
-    "O" liece-command-mode-o
-    "v" liece-command-mode+v
-    "V" liece-command-mode-v
+    "o" liece-command-set-operators
+    "v" liece-command-set-voices
     "f" liece-command-finger
     " " liece-command-nick-scroll-up
     "\177" liece-command-nick-scroll-down
     "f" liece-command-finger
     " " liece-command-nick-scroll-up
     "\177" liece-command-nick-scroll-down
@@ -381,12 +365,19 @@ is running on."
                   (eq 'liece-sentinel
                       (process-sentinel liece-server-process)))
          (set-process-sentinel liece-server-process nil))
                   (eq 'liece-sentinel
                       (process-sentinel liece-server-process)))
          (set-process-sentinel liece-server-process nil))
-       ;; We cannot send QUIT command unless the process is running.
-       (when (liece-server-opened)
-         (if quit-string
-             (liece-send "QUIT :%s" quit-string)
-           (liece-send "QUIT"))))
-    (liece-close-server-internal)))
+       (if (liece-server-opened)
+           (if quit-string
+               (liece-send "QUIT :%s" quit-string)
+             (liece-send "QUIT"))))
+    (liece-close-server-internal)
+    ;; Save settings to the `~/.liece/init.el' file.
+    (if liece-save-variables-are-dirty
+       (liece-command-save-vars))
+    ;; Reset everything.
+    (liece-clear-system)
+    (liece-window-configuration-pop)
+    ;; Allow the user to do things after cleaning up.
+    (run-hooks 'liece-exit-hook)))
 
 (defmacro liece-server-keyword-bind (plist &rest body)
   "Return a `let' form that binds all variables in PLIST.
 
 (defmacro liece-server-keyword-bind (plist &rest body)
   "Return a `let' form that binds all variables in PLIST.
@@ -553,47 +544,34 @@ If already connected, just pop up the windows."
     (liece-intl-load-catalogue))
   (if (liece-server-opened)
       (liece-configure-windows)
     (liece-intl-load-catalogue))
   (if (liece-server-opened)
       (liece-configure-windows)
-    (unwind-protect
-       (progn
-         (switch-to-buffer
-          (liece-get-buffer-create liece-command-buffer))
-         (unless (eq major-mode 'liece-command-mode)
-           (liece-command-mode))
-         (unless (liece-server-opened)
-           (liece-start-server confirm)))
-      (if (not (liece-server-opened))
-         (liece-command-quit)
-       ;; IRC server is successfully open.
-       (with-current-buffer liece-command-buffer
-         (setq mode-line-process (concat " " (liece-server-host))))
-       (let (buffer-read-only)
-         (unless liece-keep-buffers
-           (erase-buffer))
-         (sit-for 0))
-
-       (liece-initialize-buffers)
-       (liece-configure-windows)
-       (setq liece-current-channels nil)
-       (cond
-        (liece-current-channel
-         (liece-command-join liece-current-channel))
-        (liece-startup-channel
-         (liece-command-join liece-startup-channel))
-        (liece-startup-channel-list
-         (dolist (chnl liece-startup-channel-list)
-           (if (listp chnl)
-               (liece-command-join (car chnl) (cadr chnl))
-             (liece-command-join chnl)))))
-       (unless (string-equal liece-away-message "")
-         (liece-command-away liece-away-message))
-       (run-hooks 'liece-startup-hook)
-       (setq liece-obarray
-             (or liece-obarray (make-vector liece-obarray-size nil)))
-       (unless liece-timers-list-initialized-p
-         (liece-initialize-timers))
-       (liece-command-timestamp)
-       (message (substitute-command-keys
-                 "Type \\[describe-mode] for help"))))))
+    (switch-to-buffer (liece-get-buffer-create liece-command-buffer))
+    (unless (eq major-mode 'liece-command-mode)
+      (liece-command-mode))
+    (liece-start-server confirm)
+    (let (buffer-read-only)
+      (unless liece-keep-buffers
+       (erase-buffer))
+      (sit-for 0))
+    (liece-initialize-buffers)
+    (liece-configure-windows)
+    (setq liece-current-channels nil)
+    (let ((startup-channels
+          (if liece-startup-channel
+              (list liece-startup-channel)
+            liece-startup-channel-list)))
+      (dolist (chnl startup-channels)
+       (if (listp chnl)
+           (liece-command-join (car chnl) (cadr chnl))
+         (liece-command-join chnl))))
+    (unless (string-equal liece-away-message "")
+      (liece-command-away liece-away-message))
+    (run-hooks 'liece-startup-hook)
+    (setq liece-obarray
+         (or liece-obarray (make-vector liece-obarray-size nil)))
+    (unless liece-timers-list-initialized-p
+      (liece-initialize-timers))
+    (liece-command-timestamp)
+    (message (substitute-command-keys "Type \\[describe-mode] for help"))))
 
 ;;;###liece-autoload
 (defun liece-command-mode ()
 
 ;;;###liece-autoload
 (defun liece-command-mode ()
@@ -637,7 +615,7 @@ For a list of the generic commands type \\[liece-command-generic] ? RET.
          (copy-syntax-table (syntax-table)))
     (set-syntax-table liece-command-mode-syntax-table)
     (mapcar
          (copy-syntax-table (syntax-table)))
     (set-syntax-table liece-command-mode-syntax-table)
     (mapcar
-     (function (lambda (c) (modify-syntax-entry c "w")))
+     (lambda (c) (modify-syntax-entry c "w"))
      "^[]{}'`"))
 
   (run-hooks 'liece-command-mode-hook))
      "^[]{}'`"))
 
   (run-hooks 'liece-command-mode-hook))
@@ -910,7 +888,11 @@ Only used from `liece-before-insert-functions'."
        (select-window window)
        (goto-char (point-max))
        (if (null liece-scroll-step)
        (select-window window)
        (goto-char (point-max))
        (if (null liece-scroll-step)
-           (recenter (- (liece-window-height window) 1))
+           (progn
+             ;; skip last empty lines
+             (while (memq (char-before) '(?\n ?\t ?\ ))
+               (backward-char))
+             (recenter -1))
          (vertical-motion
           (- (or liece-scroll-step
                  (1+ (/ (liece-window-height window) 2)))
          (vertical-motion
           (- (or liece-scroll-step
                  (1+ (/ (liece-window-height window) 2)))