Gnus development mailing list
 help / color / mirror / Atom feed
* %(~cut X) is broken
@ 2001-09-11 22:12 Neal H Walfield
  2001-09-13 17:35 ` Martin Kretzschmar
  0 siblings, 1 reply; 3+ messages in thread
From: Neal H Walfield @ 2001-09-11 22:12 UTC (permalink / raw)


I am using a checkout of Oort Gnus from last week.  I appears that cut
maybe broken.  Here is an example of a gnus-summary-line-format where
is fails:

      "%-4,4P%U%R%z [%d] [%~(cut 3)d] %~(cut-right 4)d %-20,20n (%4L) %I%(%[ %-0,100s %]%)\n"

And, here is a sample of the output:

     1   !   [10-Sep] [Se] 10 David S. Goldberg    (  16) [ attachments in S/MIME encrypted messages ]

As you can see, %~(cut 3)d is only printing out `Se' when all I am
doing is asking it to cut off the first three characters (which, it
does do quite well, but, Gnus does not need to be so generous).

Thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: %(~cut X) is broken
  2001-09-11 22:12 %(~cut X) is broken Neal H Walfield
@ 2001-09-13 17:35 ` Martin Kretzschmar
  2001-09-14 15:12   ` ShengHuo ZHU
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Kretzschmar @ 2001-09-13 17:35 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 387 bytes --]

Neal H Walfield <neal@cs.uml.edu> writes:

[snip]
> As you can see, %~(cut 3)d is only printing out `Se' when all I am
> doing is asking it to cut off the first three characters (which, it
> does do quite well, but, Gnus does not need to be so generous).

This is a problem in gnus-correct-substring. It will never include the
last character in a substring. Here's a patch to fix that:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: correct gnus-correct-string --]
[-- Type: text/x-patch, Size: 989 bytes --]

--- /tmp/gnus-spec.el	Thu Sep 13 18:23:30 2001
+++ /tmp/gnus-spec.el.new	Thu Sep 13 18:23:30 2001
@@ -273,20 +273,21 @@
 (defun gnus-correct-substring (string start &optional end)
   (let ((wstart 0)
 	(wend 0)
+	(wseek 0)
 	(seek 0)
-	(length (length string)))
+	(length (length string))
+	(string (concat string "\0"))) 
     ;; Find the start position.
     (while (and (< seek length)
-		(< wstart start))
-      (incf wstart (gnus-char-width (aref string seek)))
+		(< wseek start))
+      (incf wseek (gnus-char-width (aref string seek)))
       (incf seek))
-    (setq wend wstart
-	  wstart seek)
+    (setq wstart seek)
     ;; Find the end position.
-    (while (and (< seek length)
+    (while (and (<= seek length)
 		(or (not end)
-		    (<= wend end)))
-      (incf wend (gnus-char-width (aref string seek)))
+		    (<= wseek end)))
+      (incf wseek (gnus-char-width (aref string seek)))
       (incf seek))
     (setq wend seek)
     (substring string wstart (1- wend))))

[-- Attachment #3: Type: text/plain, Size: 442 bytes --]


Is this too ugly or even buggy?

Looking at gnus-tilde-cut-form, I found another bug, a "," is missing,
in gnus-tilde-max-form, too, try this:

   (gnus-tilde-max-form 'bla -3) or, more high-level
   "%~(cut-right 3)L" as gnus-summary-line-format

Not only does the following patch insert the ",", it also make the
functions more readable than they were in the last weeks (IMO). If you
don't trust them, please insert at least the two ",".


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: more readable and more correct tilde-forms --]
[-- Type: text/x-patch, Size: 3316 bytes --]

--- /tmp/gnus-spec.el2052Buh	Thu Sep 13 18:58:06 2001
+++ /tmp/gnus-spec.el.new2052O4n	Thu Sep 13 18:58:06 2001
@@ -293,74 +293,46 @@
 
 (defun gnus-tilde-max-form (el max-width)
   "Return a form that limits EL to MAX-WIDTH."
-  (let ((max (abs max-width)))
-    (if (symbolp el)
-	`(if (> (,(if gnus-use-correct-string-widths
+  (let ((max (abs max-width))
+	(length-fun (if gnus-use-correct-string-widths
 		      'gnus-correct-length
-		    'length) ,el)
-		,max)
-	     ,(if (< max-width 0)
-		  `(,(if gnus-use-correct-string-widths
-			 'gnus-correct-substring
-		       'substring)
-		    ,el (- (,(if gnus-use-correct-string-widths
-				 'gnus-correct-length
-			       'length)
-			    el) ,max))
-		`(,(if gnus-use-correct-string-widths
+		    'length))
+	(substring-fun (if gnus-use-correct-string-widths
 		       'gnus-correct-substring
-		     'substring)
-		  ,el 0 ,max))
+		     'substring)))
+    (if (symbolp el)
+	`(if (> (,length-fun ,el) ,max)
+	     ,(if (< max-width 0)
+		  `(,substring-fun ,el (- (,length-fun ,el) ,max))
+		`(,substring-fun ,el 0 ,max))
 	   ,el)
       `(let ((val (eval ,el)))
-	 (if (> (,(if gnus-use-correct-string-widths
-		      'gnus-correct-length
-		    'length) val) ,max)
+	 (if (> (,length-fun val) ,max)
 	     ,(if (< max-width 0)
-		  `(,(if gnus-use-correct-string-widths
-			 'gnus-correct-substring
-		       'substring)
-		    val (- (,(if gnus-use-correct-string-widths
-				 'gnus-correct-length
-			       'length) val) ,max))
-		`(,(if gnus-use-correct-string-widths
-		       'gnus-correct-substring
-		     'substring)
-		  val 0 ,max))
+		  `(,substring-fun val (- (,length-fun val) ,max))
+		`(,substring-fun val 0 ,max))
 	   val)))))
 
 (defun gnus-tilde-cut-form (el cut-width)
   "Return a form that cuts CUT-WIDTH off of EL."
-  (let ((cut (abs cut-width)))
-    (if (symbolp el)
-	`(if (> (,(if gnus-use-correct-string-widths
+  (let ((cut (abs cut-width))
+	(length-fun (if gnus-use-correct-string-widths
 		      'gnus-correct-length
-		    'length) ,el) ,cut)
-	     ,(if (< cut-width 0)
-		  `(,(if gnus-use-correct-string-widths
-			 'gnus-correct-substring
-		       'substring) ,el 0
-		       (- (,(if gnus-use-correct-string-widths
-				'gnus-correct-length
-			      'length) el) ,cut))
-		`(,(if gnus-use-correct-string-widths
+		    'length))
+	(substring-fun (if gnus-use-correct-string-widths
 		       'gnus-correct-substring
-		     'substring) ,el ,cut))
+		     'substring)))
+    (if (symbolp el)
+	`(if (> (,length-fun ,el) ,cut)
+	     ,(if (< cut-width 0)
+		  `(,substring-fun ,el 0 (- (,length-fun ,el) ,cut))
+		`(,substring-fun ,el ,cut))
 	   ,el)
       `(let ((val (eval ,el)))
-	 (if (> (,(if gnus-use-correct-string-widths
-		      'gnus-correct-length
-		    'length) val) ,cut)
+	 (if (> (,length-fun val) ,cut)
 	     ,(if (< cut-width 0)
-		  `(,(if gnus-use-correct-string-widths
-			 'gnus-correct-substring
-		       'substring) val 0
-		       (- (,(if gnus-use-correct-string-widths
-				'gnus-correct-length
-			      'length) val) ,cut))
-		`(,(if gnus-use-correct-string-widths
-		       'gnus-correct-substring
-		     'substring) val ,cut))
+		  `(,substring-fun val 0 (- (,length-fun val) ,cut))
+		`(,substring-fun val ,cut))
 	   val)))))
 
 (defun gnus-tilde-ignore-form (el ignore-value)

[-- Attachment #5: Type: text/plain, Size: 313 bytes --]


2001-09-13  Martin Kretzschmar  <Martin.Kretzschmar@inf.tu-dresden.de>

	* gnus-spec.el (gnus-correct-substring): Still stopped one
	character before we wanted (never included last character).
	(gnus-tilde-max-form, gnus-tilde-cut-form) Made readable again,
	add missing "," (once per function)


        Martin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: %(~cut X) is broken
  2001-09-13 17:35 ` Martin Kretzschmar
@ 2001-09-14 15:12   ` ShengHuo ZHU
  0 siblings, 0 replies; 3+ messages in thread
From: ShengHuo ZHU @ 2001-09-14 15:12 UTC (permalink / raw)


Martin Kretzschmar <Martin.Kretzschmar@inf.tu-dresden.de> writes:

[...]

> 2001-09-13  Martin Kretzschmar  <Martin.Kretzschmar@inf.tu-dresden.de>
>
> 	* gnus-spec.el (gnus-correct-substring): Still stopped one
> 	character before we wanted (never included last character).
> 	(gnus-tilde-max-form, gnus-tilde-cut-form) Made readable again,
> 	add missing "," (once per function)

Installed.

ShengHuo


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-09-14 15:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-11 22:12 %(~cut X) is broken Neal H Walfield
2001-09-13 17:35 ` Martin Kretzschmar
2001-09-14 15:12   ` ShengHuo ZHU

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).