]> code.delx.au - gnu-emacs/blobdiff - lisp/erc/erc-stamp.el
Update docs for `customize-mode'
[gnu-emacs] / lisp / erc / erc-stamp.el
index 37982069abea45c7dbadb707310e8193e296e85d..a4c91ca9fb54f251e15f201bab86799569de3a70 100644 (file)
@@ -1,6 +1,6 @@
 ;;; erc-stamp.el --- Timestamping for ERC messages
 
-;; Copyright (C) 2002-2004, 2006-2014 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2004, 2006-2016 Free Software Foundation, Inc.
 
 ;; Author: Mario Lang <mlang@delysid.org>
 ;; Maintainer: emacs-devel@gnu.org
@@ -114,7 +114,7 @@ If `erc-timestamp-format' is set, this will not be used."
                 (string)))
 
 (defcustom erc-insert-away-timestamp-function
-  'erc-insert-timestamp-left-and-right
+  #'erc-insert-timestamp-left-and-right
   "Function to use to insert the away timestamp.
 
 See `erc-insert-timestamp-function' for details."
@@ -161,12 +161,12 @@ from entering them and instead jump over them."
 ;;;###autoload (autoload 'erc-timestamp-mode "erc-stamp" nil t)
 (define-erc-module stamp timestamp
   "This mode timestamps messages in the channel buffers."
-  ((add-hook 'erc-mode-hook 'erc-munge-invisibility-spec)
-   (add-hook 'erc-insert-modify-hook 'erc-add-timestamp t)
-   (add-hook 'erc-send-modify-hook 'erc-add-timestamp t))
-  ((remove-hook 'erc-mode-hook 'erc-munge-invisibility-spec)
-   (remove-hook 'erc-insert-modify-hook 'erc-add-timestamp)
-   (remove-hook 'erc-send-modify-hook 'erc-add-timestamp)))
+  ((add-hook 'erc-mode-hook #'erc-munge-invisibility-spec)
+   (add-hook 'erc-insert-modify-hook #'erc-add-timestamp t)
+   (add-hook 'erc-send-modify-hook #'erc-add-timestamp t))
+  ((remove-hook 'erc-mode-hook #'erc-munge-invisibility-spec)
+   (remove-hook 'erc-insert-modify-hook #'erc-add-timestamp)
+   (remove-hook 'erc-send-modify-hook #'erc-add-timestamp)))
 
 (defun erc-add-timestamp ()
   "Add timestamp and text-properties to message.
@@ -188,7 +188,8 @@ or `erc-send-modify-hook'."
       (add-text-properties (point-min) (point-max)
                           (list 'timestamp ct))
       (add-text-properties (point-min) (point-max)
-                          (list 'point-entered 'erc-echo-timestamp)))))
+                          (list 'cursor-sensor-functions
+                                (list #'erc-echo-timestamp))))))
 
 (defvar erc-timestamp-last-inserted nil
   "Last timestamp inserted into the buffer.")
@@ -289,8 +290,7 @@ be printed just before the window-width."
     (setq erc-timestamp-last-inserted string)
     (goto-char (point-max))
     (forward-char -1);; before the last newline
-    (let* ((current-window (get-buffer-window (current-buffer)))
-          (str-width (string-width string))
+    (let* ((str-width (string-width string))
           (pos (cond
                 (erc-timestamp-right-column erc-timestamp-right-column)
                 ((and (boundp 'erc-fill-mode)
@@ -303,8 +303,7 @@ be printed just before the window-width."
                 (t
                  (- (window-width) str-width 1))))
           (from (point))
-          (col (current-column))
-          indent)
+          (col (current-column)))
       ;; 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
@@ -319,9 +318,9 @@ be printed just before the window-width."
       (erc-put-text-property from (point) 'field 'erc-timestamp)
       (erc-put-text-property from (point) 'rear-nonsticky t)
       (when erc-timestamp-intangible
-       (erc-put-text-property from (1+ (point)) 'intangible t)))))
+       (erc-put-text-property from (1+ (point)) 'cursor-intangible t)))))
 
-(defun erc-insert-timestamp-left-and-right (string)
+(defun erc-insert-timestamp-left-and-right (_string)
   "This is another function that can be assigned to
 `erc-insert-timestamp-function'.  If the date is changed, it will
 print a blank line, the date, and another blank line.  If the time is
@@ -356,7 +355,7 @@ Return the empty string if FORMAT is nil."
        ;; inelegant, hack. -- BPT
        (and erc-timestamp-intangible
             (not erc-hide-timestamps)  ; bug#11706
-            (erc-put-text-property 0 (length ts) 'intangible t ts))
+            (erc-put-text-property 0 (length ts) 'cursor-intangible t ts))
        ts)
     ""))
 
@@ -366,15 +365,13 @@ Return the empty string if FORMAT is nil."
 ;; please modify this function and move it to a more appropriate
 ;; location.
 (defun erc-munge-invisibility-spec ()
+  (and erc-timestamp-intangible (not (bound-and-true-p cursor-intangible-mode))
+       (cursor-intangible-mode 1))
+  (and erc-echo-timestamps (not (bound-and-true-p cursor-sensor-mode))
+       (cursor-sensor-mode 1))
   (if erc-hide-timestamps
-      (setq buffer-invisibility-spec
-           (if (listp buffer-invisibility-spec)
-               (cons 'timestamp buffer-invisibility-spec)
-             (list 't 'timestamp)))
-    (setq buffer-invisibility-spec
-         (if (listp buffer-invisibility-spec)
-             (remove 'timestamp buffer-invisibility-spec)
-           (list 't)))))
+      (add-to-invisibility-spec 'timestamp)
+    (remove-from-invisibility-spec 'timestamp)))
 
 (defun erc-hide-timestamps ()
   "Hide timestamp information from display."
@@ -405,12 +402,11 @@ enabled when the message was inserted."
            (erc-munge-invisibility-spec)))
        (erc-buffer-list)))
 
-(defun erc-echo-timestamp (before now)
-  "Print timestamp text-property of an IRC message.
-Argument BEFORE is where point was before it got moved and
-NOW is position of point currently."
-  (when erc-echo-timestamps
-    (let ((stamp (get-text-property now 'timestamp)))
+(defun erc-echo-timestamp (window _before dir)
+  "Print timestamp text-property of an IRC message."
+  (when (and erc-echo-timestamps (eq 'entered dir))
+    (let* ((now (window-point window))
+          (stamp (get-text-property now 'timestamp)))
       (when stamp
        (message "%s" (format-time-string erc-echo-timestamp-format
                                          stamp))))))