From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/38731 Path: main.gmane.org!not-for-mail From: Martin Kretzschmar Newsgroups: gmane.emacs.gnus.general Subject: Re: %(~cut X) is broken Date: Thu, 13 Sep 2001 19:35:01 +0200 Sender: martin@mogli.aximilation.org Message-ID: <87pu8vvvsq.fsf@mogli.aximilation.org> References: <878zfl4bs6.fsf@bassanio.walfield.org> NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1035174547 24008 80.91.224.250 (21 Oct 2002 04:29:07 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 21 Oct 2002 04:29:07 +0000 (UTC) Return-Path: Return-Path: Original-Received: (qmail 11118 invoked from network); 13 Sep 2001 17:39:05 -0000 Original-Received: from mail.gmx.net (213.165.64.20) by gnus.org with SMTP; 13 Sep 2001 17:39:05 -0000 Original-Received: (qmail 10636 invoked by uid 0); 13 Sep 2001 17:38:35 -0000 Original-Received: from h590.ibc.de.easynet.net (HELO mogli.aximilation.org) (212.224.50.78) by mail.gmx.net (mp001-rz3) with SMTP; 13 Sep 2001 17:38:35 -0000 Original-To: ding@gnus.org In-Reply-To: <878zfl4bs6.fsf@bassanio.walfield.org> (Neal H Walfield's message of "Wed, 12 Sep 2001 00:12:41 +0200") User-Agent: Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.0.105 Original-Lines: 37 Xref: main.gmane.org gmane.emacs.gnus.general:38731 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:38731 --=-=-= Neal H Walfield 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: --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=correct-substring.diff Content-Description: correct gnus-correct-string --- /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)))) --=-=-= 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 ",". --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=tilde-cut-max.diff Content-Description: more readable and more correct tilde-forms --- /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) --=-=-= 2001-09-13 Martin Kretzschmar * 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 --=-=-=--