Catch up with the changes incorporated in XEmacs package.
[elisp/liece.git] / lisp / liece.el
index 7471440..ecb2aeb 100644 (file)
     "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)
@@ -202,7 +197,6 @@ If optional argument SAFE is nil, overwrite previous definitions."
     "/" 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
@@ -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
-    "u" liece-command-lusers
-    "U" liece-command-userhost
     "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
-    [(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
@@ -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
-    "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
@@ -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
-    "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
@@ -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
-    "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
-    "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
@@ -381,12 +365,19 @@ is running on."
                   (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.
@@ -444,8 +435,6 @@ If optional argument SERVICE is non-nil, open by the service name."
     (if (and (memq type '(rlogin telnet)) relay)
        (setq liece-tcp-relay-host relay))
     (setq liece-tmp-server-name host)
-    (unless (string-match "^[^\\[]" host)
-      (setq host (substring host 1 (1- (length host)))))
     (setq liece-server-process (liece-open-server-internal host service type))
     (setq liece-after-registration nil)
     (liece-maybe-poll)
@@ -458,8 +447,8 @@ If optional argument SERVICE is non-nil, open by the service name."
       (set-process-sentinel liece-server-process 'liece-sentinel)
       (set-process-filter liece-server-process 'liece-filter)
       (if (or liece-ask-for-password liece-reconnect-with-password)
-         (let ((passwd-echo ?*) password)
-           (setq password (read-passwd (_ "Server Password: ")))
+         (let ((password
+                (liece-read-passwd (_ "Server Password: "))))
            (or (string= password "")
                (setq liece-password password))))
       (if liece-password
@@ -475,7 +464,7 @@ If optional argument SERVICE is non-nil, open by the service name."
       ;; notify the real nickname to the user.
       (or liece-real-nickname
          (setq liece-real-nickname
-               (truncate-string liece-nickname liece-nick-max-length)))
+               (truncate-string-to-width liece-nickname liece-nick-max-length)))
       (setq liece-nickname-last liece-real-nickname
            liece-nick-accepted 'sent
            liece-after-registration t))))
@@ -555,47 +544,34 @@ If already connected, just pop up the 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 ()
@@ -639,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
-     (function (lambda (c) (modify-syntax-entry c "w")))
+     (lambda (c) (modify-syntax-entry c "w"))
      "^[]{}'`"))
 
   (run-hooks 'liece-command-mode-hook))
@@ -888,7 +864,7 @@ If such a buffer is found, shrink it."
              (delete-region (point-min)
                             (progn
                               (goto-char (- (buffer-size)
-                                            liece-buffer-default-size))
+                                            liece-buffer-min-size))
                               (beginning-of-line -1)
                               (point)))
              (garbage-collect)
@@ -899,26 +875,23 @@ If such a buffer is found, shrink it."
 Only used from `liece-before-insert-functions'."
   (and (> liece-buffer-check-interval 0)
        (or (null liece-buffer-last-check-time)
-          (> (liece-time-difference liece-buffer-last-check-time
-                                    (current-time))
+          (> (liece-time-difference (current-time)
+                                    liece-buffer-last-check-time)
              liece-buffer-check-interval))
        (liece-check-buffers)))
 
 (defun liece-refresh-buffer-window (buffer)
   "Center point in window of BUFFER and redisplay frame."
-  (let ((window (liece-get-buffer-window buffer)))
-    (when (and window (not (pos-visible-in-window-p (point-max) window)))
+  (let ((window (liece-get-buffer-window buffer))
+       (last-point (point-max)))
+    ;; skip last white spaces
+    (while (memq (char-before last-point) '(?\n ?\t ?\ ))
+      (setq last-point (1- last-point)))
+    (when (and window (not (pos-visible-in-window-p last-point window)))
       (save-selected-window
        (select-window window)
-       (goto-char (point-max))
-       (if (null liece-scroll-step)
-           (recenter (- (liece-window-height window) 1))
-         (vertical-motion
-          (- (or liece-scroll-step
-                 (1+ (/ (liece-window-height window) 2)))
-             (liece-window-height window)))
-         (set-window-start window (point))
-         (goto-char (point-max)))))))
+       (goto-char last-point)
+       (recenter (- (or liece-scroll-step 1)))))))
 
 (defmacro liece-save-point (&rest body)
   "Execute BODY, then goto the point that was around before BODY."