Gnus development mailing list
 help / color / mirror / Atom feed
* Yet another washing function.
@ 1997-10-05  0:47 St. Suika Roberts
  1997-10-05 11:27 ` Kim-Minh Kaplan
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: St. Suika Roberts @ 1997-10-05  0:47 UTC (permalink / raw)


I started working on this one back in May, but I only got it to where
I like it today ^^;;

It fixes M$Word style `smart quotes' back to normal ascii ones.
------------------------------ cut here ------------------------------
(defun gnus-article-fix-m$word ()
  "Fix M$Word smartquotes in an article."
  (interactive)
  (save-excursion
    (with-current-buffer gnus-article-buffer
     (let ((buffer-read-only nil))
       (goto-char (point-min))
       (while (search-forward "\221" nil t)
	 (replace-match "`" t t))
       (goto-char (point-min))
       (while (search-forward "\222" nil t)
	 (replace-match "'" t t))
       (goto-char (point-min))
       (while (search-forward "\223" nil t)
	 (replace-match "\"" t t))
       (goto-char (point-min))
       (while (search-forward "\224" nil t)
	 (replace-match "\"" t t))))))
------------------------------ cut here ------------------------------

I was thinking `W W m' might be a good binding for it.

Thanks,
	Suika (yes, this makes four passes through the buffer.  If
	elisp has a way to do this in one pass I'd be interested in
	learning about it)
-- 
		wroberts@tvi.cc.nm.us
"Amazing what caffeine and no sense of self-preservation can do..."
	<a href="http://studentweb.tulane.edu/~wrobert2">lists</a>


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

* Re: Yet another washing function.
  1997-10-05  0:47 Yet another washing function St. Suika Roberts
@ 1997-10-05 11:27 ` Kim-Minh Kaplan
       [not found] ` <x7iuvc8f0r.fsf@peorth.gweep.net>
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Kim-Minh Kaplan @ 1997-10-05 11:27 UTC (permalink / raw)


>>>>> On October  4, 1997, St Suika Roberts said:

Suika> If elisp has a way to do this in one pass I'd be interested in
Suika> learning about it

The function `skip-chars-forward' and `following-char' could do it.

You could also do it by tweaking the display table of the article
buffer.  It would probably be more efficient, but it will be more
difficult to remove the special display properties for normal
articles.

Kim-Minh.


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

* Re: Yet another washing function.
       [not found] ` <x7iuvc8f0r.fsf@peorth.gweep.net>
@ 1997-10-06  0:57   ` Greg Stark
  1997-10-08 16:23     ` Lars Balker Rasmussen
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Stark @ 1997-10-06  0:57 UTC (permalink / raw)



Please try to avoid generating garbage whenever possible, the regular
expression functions generate a lot of wasted memory and the loops in elisp
are very inefficient compared to using primitives that do loops in C. Also,
replace-match probably moves the gap to that point which means you're doing
the equivalent of memoving the entire article a small bit at a time. 

I've noticed that article washing is a noticeable delay. It might be worth
looking through the existing washing functions for code that generates excess
garbage, do loops in elisp that can be done in C with primitives, or move the
gap unecessarily. Here's an implementation that does none of these:

(subst-char-in-region (point-min) (point-max) ?\221 ?`)
(subst-char-in-region (point-min) (point-max) ?\222 ?')
(subst-char-in-region (point-min) (point-max) ?\223 ?\")
(subst-char-in-region (point-min) (point-max) ?\224 ?\")

An even better alternative might be to use translate-region but it's a bit
awkward and likely to cause problems with XEmacs 20 and Emacs 20 where
characters and integers are distinct. It may not actually be faster than a few
loops through the text, though i'm not sure if the break-even point would be
more or less than four.

(let ((x (make-string 225 ?x))
      (i -1))
  (while (< (incf i) (length x))
    (aset x i i))
  (aset x ?\221 ?`)
  (aset x ?\222 ?')
  (aset x ?\223 ?\")
  (aset x ?\224 ?\")
  x
  (translate-region (point-min) (point-max) x))


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

* Re: Yet another washing function.
  1997-10-05  0:47 Yet another washing function St. Suika Roberts
  1997-10-05 11:27 ` Kim-Minh Kaplan
       [not found] ` <x7iuvc8f0r.fsf@peorth.gweep.net>
@ 1997-10-06 19:57 ` William M. Perry
  1997-10-07 14:06 ` Michael Welsh Duggan
  1997-10-12 14:53 ` Lars Magne Ingebrigtsen
  4 siblings, 0 replies; 9+ messages in thread
From: William M. Perry @ 1997-10-06 19:57 UTC (permalink / raw)
  Cc: ding

"St. Suika Roberts" <wrobert2@mailhost.tcs.tulane.edu> writes:

> I started working on this one back in May, but I only got it to where
> I like it today ^^;;
> 
> It fixes M$Word style `smart quotes' back to normal ascii ones.
> ------------------------------ cut here ------------------------------
> (defun gnus-article-fix-m$word ()
>   "Fix M$Word smartquotes in an article."
>   (interactive)
>   (save-excursion
>     (with-current-buffer gnus-article-buffer
>      (let ((buffer-read-only nil))
>        (goto-char (point-min))
>        (while (search-forward "\221" nil t)
> 	 (replace-match "`" t t))
>        (goto-char (point-min))
>        (while (search-forward "\222" nil t)
> 	 (replace-match "'" t t))
>        (goto-char (point-min))
>        (while (search-forward "\223" nil t)
> 	 (replace-match "\"" t t))
>        (goto-char (point-min))
>        (while (search-forward "\224" nil t)
> 	 (replace-match "\"" t t))))))

  I would use subst-char-in-region:

(defun gnus-article-fix-quotes ()
  (interactive)
  (with-current-buffer gnus-article-buffer
    (let ((buffer-read-only nil)
          (inhibit-read-only t))
      (subst-char-in-region (point-min) (point-max) ?\221 ?`)
      (subst-char-in-region (point-min) (point-max) ?\222 ?')
      (subst-char-in-region (point-min) (point-max) ?\223 ?\")
      (subst-char-in-region (point-min) (point-max) ?\224 ?\"))))

-Bill P.


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

* Re: Yet another washing function.
  1997-10-05  0:47 Yet another washing function St. Suika Roberts
                   ` (2 preceding siblings ...)
  1997-10-06 19:57 ` William M. Perry
@ 1997-10-07 14:06 ` Michael Welsh Duggan
  1997-10-12 14:53 ` Lars Magne Ingebrigtsen
  4 siblings, 0 replies; 9+ messages in thread
From: Michael Welsh Duggan @ 1997-10-07 14:06 UTC (permalink / raw)


"St. Suika Roberts" <wrobert2@mailhost.tcs.tulane.edu> writes:

> I started working on this one back in May, but I only got it to where
> I like it today ^^;;
> 
> It fixes M$Word style `smart quotes' back to normal ascii ones.
> ------------------------------ cut here ------------------------------
> (defun gnus-article-fix-m$word ()
>   "Fix M$Word smartquotes in an article."
>   (interactive)
>   (save-excursion
>     (with-current-buffer gnus-article-buffer
>      (let ((buffer-read-only nil))
>        (goto-char (point-min))
>        (while (search-forward "\221" nil t)
>        (replace-match "`" t t))
>        (goto-char (point-min))
>        (while (search-forward "\222" nil t)
>        (replace-match "'" t t))
>        (goto-char (point-min))
>        (while (search-forward "\223" nil t)
>        (replace-match "\"" t t))
>        (goto-char (point-min))
>        (while (search-forward "\224" nil t)
>        (replace-match "\"" t t))))))
> ------------------------------ cut here ------------------------------
> 
> I was thinking `W W m' might be a good binding for it.

Hmm... I do something similar in mine:

(defun md5i-special-display-table ()
  (let ((bdt (make-display-table)))
    (aset bdt 13  [])                   ;Zap ^Ms
    (aset bdt 25  [])                   ;Zap ^Ys
    (aset bdt 133 [?. ?. ?.])           ;\205 = ...
    (aset bdt 145 [?`])                 ;\221 = `
    (aset bdt 146 [?'])                 ;\222 = '
    (aset bdt 147 [?\"])                ;\223 = "
    (aset bdt 148 [?\"])                ;\224 = "
    (aset bdt 149 [?*])                 ;\225 = *
    (aset bdt 150 [?- ?-])              ;\226 = --
    (aset bdt 151 [?- ?- ?-])           ;\227 = ---
    (aset bdt 153 [?( ?T ?m ?)])        ;\231 = (Tm)
    (setq buffer-display-table bdt)))

I then placed this in the gnus-article-display-hook.  (The list is not
complete, however, as I have added the entries as I have come across
them.)

-- 
Michael Duggan
(md5i@cs.cmu.edu)


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

* Re: Yet another washing function.
  1997-10-06  0:57   ` Greg Stark
@ 1997-10-08 16:23     ` Lars Balker Rasmussen
  1997-11-13 18:06       ` Lars Balker Rasmussen
  0 siblings, 1 reply; 9+ messages in thread
From: Lars Balker Rasmussen @ 1997-10-08 16:23 UTC (permalink / raw)


Greg Stark <gsstark@MIT.EDU> writes:
> I've noticed that article washing is a noticeable delay. 

Quite!  If I try to view a LARGE article which I know what's in, I might
as well press C-g after a couple of seconds to avoid waiting for ages.
The article appears pretty much like I'd expect if I'd waited the entire
time, but I haven't looked into it further.  That's annoying...

Relevant hooks (that I know of):

gnus-article-display-hook's value is 
(gnus-article-highlight gnus-article-hide-pgp gnus-article-hide-headers-if-wanted gnus-article-hide-boring-headers gnus-article-treat-overstrike gnus-article-maybe-highlight)

gnus-article-prepare-hook's value is 
(gnus-article-de-quoted-unreadable)

> (subst-char-in-region (point-min) (point-max) ?\221 ?`)
> (subst-char-in-region (point-min) (point-max) ?\222 ?')
> (subst-char-in-region (point-min) (point-max) ?\223 ?\")
> (subst-char-in-region (point-min) (point-max) ?\224 ?\")

Might as well have NOUNDO set to t, right?
-- 
Lars Balker Rasmussen, Software Engineer, Mjolner Informatics ApS
lbr@mjolner.dk


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

* Re: Yet another washing function.
  1997-10-05  0:47 Yet another washing function St. Suika Roberts
                   ` (3 preceding siblings ...)
  1997-10-07 14:06 ` Michael Welsh Duggan
@ 1997-10-12 14:53 ` Lars Magne Ingebrigtsen
  4 siblings, 0 replies; 9+ messages in thread
From: Lars Magne Ingebrigtsen @ 1997-10-12 14:53 UTC (permalink / raw)


"St. Suika Roberts" <wrobert2@mailhost.tcs.tulane.edu> writes:

> I started working on this one back in May, but I only got it to where
> I like it today ^^;;

I've added two functions; `article-translate-characters' that does
what you'd think; and `gnus-article-treat-dumbquotes' that uses this
function to do its work.  Perhaps the command could take a symbolic
prefix to do other types of translations?  Anyone have good "tr"
commands that they find useful?

-- 
(domestic pets only, the antidote for overdose, milk.)
  larsi@gnus.org * Lars Magne Ingebrigtsen


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

* Re: Yet another washing function.
  1997-10-08 16:23     ` Lars Balker Rasmussen
@ 1997-11-13 18:06       ` Lars Balker Rasmussen
  1997-11-13 21:37         ` Lars Magne Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Lars Balker Rasmussen @ 1997-11-13 18:06 UTC (permalink / raw)


I wrote on October 8 1997:
> Greg Stark <gsstark@MIT.EDU> writes:
>> I've noticed that article washing is a noticeable delay. 
> 
> Quite!  If I try to view a LARGE article which I know what's in, I might
> as well press C-g after a couple of seconds to avoid waiting for ages.
> The article appears pretty much like I'd expect if I'd waited the entire
> time, but I haven't looked into it further.  That's annoying...

After receiving a few 30000-lines mail these last couple of days I broke
down and investigated a bit more.  The HUGE time-wasters are perhaps
unsurprisingly the highlight functions in gnus-article-display-hook.

By applying the following nasty hack to 5.4.67's gnus-art.el I'm a much
happier man.  Is it possible to clean up the highlight functions[1] to
make them more efficient, or could my hack be cleaned up[2] and used?

Whatever, 30000-line mails now pops up in an Article buffer the instant
I want them, not after I've pressed C-g...

Cheers,
Lars

----------------------------------------------------------------------
--- gnus-art.el.orig    Sat Sep 13 15:43:22 1997
+++ gnus-art.el Thu Nov 13 18:53:55 1997
@@ -1901,6 +1901,14 @@
        (forward-line line)
        (point)))))
 
+(defun gnus-run-article-display-hook ()
+  (if (and (gnus-fetch-field "Lines")
+          (> (string-to-number (gnus-fetch-field "Lines")) 1000))
+      (loop for hook in gnus-article-display-hook do
+           (if (not (string-match "highlight" (symbol-name hook)))
+               (funcall hook)))
+    (run-hooks 'gnus-article-display-hook)))
+
 (defun gnus-article-prepare (article &optional all-headers header)
   "Prepare ARTICLE in article mode buffer.
 ARTICLE should either be an article number or a Message-ID.
@@ -2010,7 +2018,7 @@
                      (funcall gnus-show-mime-method)
                    (funcall gnus-decode-encoded-word-method)))
                ;; Perform the article display hooks.
-               (run-hooks 'gnus-article-display-hook))
+               (gnus-run-article-display-hook))
              ;; Do page break.
              (goto-char (point-min))
              (setq gnus-page-broken
----------------------------------------------------------------------

[1] I noticed that I have both gnus-article-highlight and
    gnus-article-maybe-highlight in my gnus-article-display-hook.  
    I suppose I have a reason for that.
[2] I suppose a variable instead of my hardcoded 1000 would be nice :-)
-- 
Lars Balker Rasmussen, Software Engineer, Mjolner Informatics ApS
lbr@mjolner.dk


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

* Re: Yet another washing function.
  1997-11-13 18:06       ` Lars Balker Rasmussen
@ 1997-11-13 21:37         ` Lars Magne Ingebrigtsen
  0 siblings, 0 replies; 9+ messages in thread
From: Lars Magne Ingebrigtsen @ 1997-11-13 21:37 UTC (permalink / raw)


Lars Balker Rasmussen <lbr@mjolner.dk> writes:

> By applying the following nasty hack to 5.4.67's gnus-art.el I'm a much
> happier man.  Is it possible to clean up the highlight functions[1] to
> make them more efficient, or could my hack be cleaned up[2] and used?

I've now added this to the todo list.

-- 
(domestic pets only, the antidote for overdose, milk.)
  larsi@gnus.org * Lars Magne Ingebrigtsen


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

end of thread, other threads:[~1997-11-13 21:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-05  0:47 Yet another washing function St. Suika Roberts
1997-10-05 11:27 ` Kim-Minh Kaplan
     [not found] ` <x7iuvc8f0r.fsf@peorth.gweep.net>
1997-10-06  0:57   ` Greg Stark
1997-10-08 16:23     ` Lars Balker Rasmussen
1997-11-13 18:06       ` Lars Balker Rasmussen
1997-11-13 21:37         ` Lars Magne Ingebrigtsen
1997-10-06 19:57 ` William M. Perry
1997-10-07 14:06 ` Michael Welsh Duggan
1997-10-12 14:53 ` Lars Magne Ingebrigtsen

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).