Here's some more tmda-pending hackery for your perusal, as a diff
against CVS HEAD.  The main changes are to make the buffer contents more
readable, and to fix (or maybe just work around) what I hope is the last
format string error.  If you would rather have me commit these directly,
my SF user ID is rgrjr.  TIA,

                                        -- Bob Rogers
                                           http://rgrjr.dyndns.org/

------------------------------------------------------------------------
Index: contrib/ChangeLog
===================================================================
RCS file: /cvsroot/tmda/tmda/contrib/ChangeLog,v
retrieving revision 1.103
diff -u -r1.103 ChangeLog
--- contrib/ChangeLog   29 Apr 2004 15:24:15 -0000      1.103
+++ contrib/ChangeLog   7 Nov 2004 03:17:39 -0000
@@ -1,3 +1,15 @@
+2004-11-06  Bob Rogers  <[EMAIL PROTECTED]>
+
+       * tmda.el (tmda-pending-minimum-user-name-size):  New var.
+       * tmda.el (tmda-pending-refresh-buffer):  Reformat the detail
+       lines to use adaptive fixed-width fields, so that a long user name
+       doesn't make all the subjects disappear.
+       * tmda.el (tmda-pending-regexp-delete):  New cmd, not bound to a
+       key until I figure out whether it's worth it.
+       * tmda.el (tmda-pending-apply-changes):  Don't use format to
+       construct commands for shell-command-to-string.  This seems to fix
+       a format string bug (at least in FSF 21.3), though I'm not sure why.
+
 2004-04-03  Bob Rogers  <[EMAIL PROTECTED]>
 
         * tmda.el (tmda-pending-buffer-kill):  FSF emacs `=' expects 2 args.
Index: contrib/tmda.el
===================================================================
RCS file: /cvsroot/tmda/tmda/contrib/tmda.el,v
retrieving revision 1.6
diff -u -r1.6 tmda.el
--- contrib/tmda.el     29 Apr 2004 15:24:16 -0000      1.6
+++ contrib/tmda.el     7 Nov 2004 03:17:40 -0000
@@ -598,8 +598,17 @@
   "*Arguments to pass to tmda-pending to generate a summary.")
 
 (defvar tmda-pending-truncate-lines t
-  "*If value is t, truncate lines in the tmda-pending buffer to the
-current window size.")
+  "*If value is true, truncate lines in the tmda-pending buffer to the
+current window width.")
+
+(defvar tmda-pending-minimum-user-name-size 20
+  "*When tmda-pending-truncate-lines is true, this controls the minimum size to
+which the user name field will be truncated.  If further truncation is needed,
+it will come out of the subject field.
+
+If tmda-pending-minimum-user-name-size is null, then the name is never
+truncated.  However, this may not be desirable, as a single long name would
+make all the subjects disappear.")
 
 (defun tmda-pending-refresh-buffer ()
   (interactive)
@@ -612,23 +621,58 @@
   (insert "\n-*- Complete list of pending messages -*-\n\n")
   (insert (shell-command-to-string
           (concat "tmda-pending " tmda-pending-summary-args)))
-  ;; put tag placeholders at the start of lines with msgids
-  (save-excursion
-    (let ((winwidth (1- (window-width))))
+  ;; Reformat the raw tmda-pending output.
+  (let* ((widths (list 0 0 0))
+        (winwidth (1- (window-width)))
+        (avail-width (- winwidth 9)))
+    ;; Figure out how big to make the fields.
+    (save-excursion
+      (goto-char (point-min))
+      (while (not (eobp))
+       (if (looking-at "\\([0-9.]+\\.msg\\)\t\\([^\t\n]*\\)\t\\([^\t\n]*\\)")
+           (let ((n 1))
+             (while (<= n 3)
+               (setcar (nthcdr (1- n) widths)
+                       (max (length (match-string n))
+                            (nth (1- n) widths)))
+               (setq n (1+ n)))))
+       (forward-line 1)))
+    (when tmda-pending-truncate-lines
+      ;; If the lines would be too long, then start trimming fields.  If
+      ;; tmda-pending-minimum-user-name-size is not null, then trim the sender
+      ;; name field, but never shorter than tmda-pending-minimum-user-name-size
+      ;; characters.  If that's not enough, then trim the subject field to fit.
+      ;; Don't trim IDs at all, because that makes them useless.
+      (let ((overrun (- (apply '+ widths) avail-width))
+           (name-width (car (cdr widths))))
+       (cond ((and (> overrun 0)
+                   tmda-pending-minimum-user-name-size)
+               (setcar (cdr widths)
+                       (max (- name-width overrun)
+                            tmda-pending-minimum-user-name-size))
+               (setq overrun (- (apply '+ widths) avail-width))))
+       (if (> overrun 0)
+           (setcar (cdr (cdr widths)) (- (nth 2 widths) overrun)))))
+    ;; Reformat the message lines according to the field widths, putting tag
+    ;; placeholders at the start.
+    (save-excursion
       (goto-char (point-min))
       (while (not (eobp))
-        (cond ((looking-at ".*[0-9.]+\\.msg[\t ]")
-               (insert "[ ] "))
-              ((looking-at "^$"))      ; do nothing
-              ((looking-at "^-\\*- ")) ; again, do nothing
-              (t
-               (insert "    ")))
-        (when tmda-pending-truncate-lines
-          (let ((curwidth (save-excursion (end-of-line) (current-column))))
-            (when (> curwidth winwidth)
-              (save-excursion
-                (move-to-column winwidth)
-                (kill-line)))))
+       (cond ((looking-at
+               "\\([0-9.]+\\.msg\\)\t\\([^\t\n]*\\)\t\\([^\t\n]*\\)")
+              (if tmda-pending-truncate-lines
+                  (replace-match
+                    (mapconcat (lambda (n)
+                                 (let* ((string (match-string n))
+                                        (width (nth (1- n) widths))
+                                        (pad (- width (length string))))
+                                   (if (<= pad 0)
+                                       (substring string 0 width)
+                                       (concat string (make-string pad ? )))))
+                               '(1 2 3) "  ")
+                    t t))
+              (beginning-of-line)
+              (insert "[ ]  ")))
         (forward-line))))
   (insert (concat "\n" tmda-pending-help-text))
   (goto-char (point-min))
@@ -694,6 +738,13 @@
        (tmda-pending-tag-command " ")
        (error "No previous message."))))
 
+(defun tmda-pending-regexp-delete (regexp)
+  "Delete all pending messages that match a regular expression."
+  (interactive "sDelete messages matching: ")
+  (let ((tmda-pending-tag-auto-advance nil))
+    (while (re-search-forward regexp nil t)
+      (tmda-pending-tag-command "d"))))
+
 (defun tmda-pending-changelist ()
   (save-excursion
     (goto-char (point-min))
@@ -718,13 +769,13 @@
     (when (< 0 (length dels))
       (message "Processing...deletes")
       (message "%s" (shell-command-to-string
-                    (format "tmda-pending -b -d %s"
-                            (mapconcat 'identity dels " ")))))
+                     (mapconcat 'identity (cons "tmda-pending -b -d" dels)
+                                " "))))
     (when (< 0 (length rels))
       (message "Processing...releases")
       (message "%s" (shell-command-to-string
-                    (format "tmda-pending -b -r %s"
-                            (mapconcat 'identity rels " "))))))
+                     (mapconcat 'identity (cons "tmda-pending -b -r" rels)
+                                " ")))))
   (sleep-for 0.5)
   (message "Processing...refreshing pending list")
   (tmda-pending-refresh-buffer)
_________________________________________________
tmda-workers mailing list ([EMAIL PROTECTED])
http://tmda.net/lists/listinfo/tmda-workers

Reply via email to