Gnus development mailing list
 help / color / mirror / Atom feed
From: Martin Kretzschmar <Martin.Kretzschmar@inf.tu-dresden.de>
Subject: Re: %(~cut X) is broken
Date: Thu, 13 Sep 2001 19:35:01 +0200	[thread overview]
Message-ID: <87pu8vvvsq.fsf@mogli.aximilation.org> (raw)
In-Reply-To: <878zfl4bs6.fsf@bassanio.walfield.org> (Neal H Walfield's message of "Wed, 12 Sep 2001 00:12:41 +0200")

[-- 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

  reply	other threads:[~2001-09-13 17:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-11 22:12 Neal H Walfield
2001-09-13 17:35 ` Martin Kretzschmar [this message]
2001-09-14 15:12   ` ShengHuo ZHU

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87pu8vvvsq.fsf@mogli.aximilation.org \
    --to=martin.kretzschmar@inf.tu-dresden.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).