erc-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Erc-commit] [commit][emacs22] Make timestamps work better when erc-time


From: mwolson
Subject: [Erc-commit] [commit][emacs22] Make timestamps work better when erc-timestamp-right-column is nil.
Date: Sun, 14 Oct 2007 00:48:01 -0400

commit c931645cd0e2ea512d103d69e73113fcea4c3f05
Author: Michael Olson <address@hidden>
Date:   Sat Feb 11 23:50:32 2006 +0000

    Make timestamps work better when erc-timestamp-right-column is nil.
    
    * erc-stamp.el (erc-timestamp-use-align-to): Renamed from
      `erc-timestamp-right-align-by-pixel'.  Set the default based on whether
      we are in Emacs 22, and using X.  Improve documentation.
      (erc-insert-aligned): Remove calculation of offset, since :align-to pos
      works after all.  Unlike the previous solution, this one works when
      erc-stamp.el is compiled.
      (erc-insert-timestamp-right): Don't add length of string, and then
      later remove its displayed width.  This puts timestamps after
      erc-fill-column when erc-timestamp-right-column is nil, rather than
      before it.  It also fixes a subtle bug.  Remove use of
      `current-window', since there is no variable by that name in Emacs21,
      Emacs22, or XEmacs21 beta.  Check to see whether `erc-fill-column' is
      non-nil before using it.
    git-archimport-id: address@hidden/erc--cvs--0--patch-113

diff --git a/ChangeLog b/ChangeLog
index d35067a..6022f52 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,20 @@
        (erc-capab-send-identify-messages, erc-capab-identify-activate):
        Minor whitespace fix in code.
 
+       * erc-stamp.el (erc-timestamp-use-align-to): Renamed from
+       `erc-timestamp-right-align-by-pixel'.  Set the default based on
+       whether we are in Emacs 22, and using X.  Improve documentation.
+       (erc-insert-aligned): Remove calculation of offset, since
+       :align-to pos works after all.  Unlike the previous solution, this
+       one works when erc-stamp.el is compiled.
+       (erc-insert-timestamp-right): Don't add length of string, and then
+       later remove its displayed width.  This puts timestamps after
+       erc-fill-column when erc-timestamp-right-column is nil, rather
+       than before it.  It also fixes a subtle bug.  Remove use of
+       `current-window', since there is no variable by that name in
+       Emacs21, Emacs22, or XEmacs21 beta.  Check to see whether
+       `erc-fill-column' is non-nil before using it.
+
 2006-02-11  Diane Murray  <address@hidden>
 
        * erc-list.el: Define `list' module which sets the alias
diff --git a/erc-stamp.el b/erc-stamp.el
index ea2cb78..cf5a37e 100644
--- a/erc-stamp.el
+++ b/erc-stamp.el
@@ -183,11 +183,17 @@ the correct column."
          (integer :tag "Column number")
          (const :tag "Unspecified" nil)))
 
-(defcustom erc-timestamp-right-align-by-pixel nil
-  "*If non-nil, insert the right timestamp based on a pixel value.
-This is needed when variable-width text precedes a timestamp.
+(defcustom erc-timestamp-use-align-to (and (not (featurep 'xemacs))
+                                          (>= emacs-major-version 22)
+                                          (eq window-system 'x))
+  "*If non-nil, use the :align-to display property to align the stamp.
+This gives better results when variable-width characters (like
+Asian language characters and math symbols) precede a timestamp.
 Unfortunately, it only works in Emacs 22 and when using the X
-Window System."
+Window System.
+
+A side effect of enabling this is that there will only be one
+space before a right timestamp in any saved logs."
   :group 'erc-stamp
   :type 'boolean)
 
@@ -203,18 +209,15 @@ Window System."
     (insert s)))
 
 (defun erc-insert-aligned (string pos)
-  "Insert STRING based on a fraction of the width of the buffer.
-Fraction is roughly (/ POS (window-width)).
+  "Insert STRING at the POSth column.
 
-If `erc-timestamp-right-align-by-pixel' is nil, insert STRING at the
-POSth column, without using pixel coordinates."
-  (if (not erc-timestamp-right-align-by-pixel)
+If `erc-timestamp-use-align-to' is t, use the :align-to display
+property to get to the POSth column."
+  (if (not erc-timestamp-use-align-to)
       (indent-to pos)
     (insert " ")
-    (let ((offset (floor (* (/ (1- pos) (window-width) 1.0)
-                           (nth 2 (window-inside-pixel-edges))))))
-      (put-text-property (1- (point)) (point) 'display
-                        `(space :align-to (,offset)))))
+    (put-text-property (1- (point)) (point) 'display
+                      (list 'space ':align-to pos)))
   (insert string))
 
 (defun erc-insert-timestamp-right (string)
@@ -241,30 +244,26 @@ be printed just before the window-width."
     (forward-char -1);; before the last newline
     (let* ((current-window (get-buffer-window (current-buffer)))
           (pos (cond
-                (erc-timestamp-right-column
-                 (+ erc-timestamp-right-column (length string)))
+                (erc-timestamp-right-column erc-timestamp-right-column)
                 ((and (boundp 'erc-fill-mode)
                       erc-fill-mode
-                      (boundp 'erc-fill-column))
+                      (boundp 'erc-fill-column)
+                      erc-fill-column)
                  (1+ erc-fill-column))
-                (current-window
-                 (- (window-width current-window)
-                    1))
                 (fill-column
                  (1+ fill-column))
                 (t
                  (- (window-width)
+                    (string-width string)
                     1))))
           (from (point))
           (col (current-column))
           indent)
-      ;; deal with variable-width characters
-      (setq pos (- pos (string-width string))
-           ;; The following is a kludge that works with most
-           ;; international input.  It is now only used to calculate
-           ;; whether to move to the next line before inserting a
-           ;; stamp.
-           col (+ col (ceiling (/ (- col (- (point) (point-at-bol))) 1.6))))
+      ;; The following is a kludge used to calculate whether to move
+      ;; to the next line before inserting a stamp.  It allows for
+      ;; some margin of error if what is displayed on the line differs
+      ;; from the number of characters on the line.
+      (setq col (+ col (ceiling (/ (- col (- (point) (point-at-bol))) 1.6))))
       (if (< col pos)
          (erc-insert-aligned string pos)
        (newline)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]