Gnus development mailing list
 help / color / mirror / Atom feed
From: sigurd@12move.de (Karl Pflästerer)
Subject: Re: A lot of questions concerning `gnus-score-edit-file-at-point'
Date: Tue, 30 Dec 2003 00:10:52 +0100	[thread overview]
Message-ID: <m3isjzp8z2.fsf@hamster.pflaesterer.de> (raw)
In-Reply-To: <v9ad5buy06.fsf@marauder.physik.uni-ulm.de>

On 29 Dec 2003, Reiner Steib <- 4.uce.03.r.s@nurfuerspam.de wrote:

> On Mon, Dec 29 2003, Karl Pflästerer wrote:

>> That raises another question: is the `(setq truncate-lines t)' really
>> necessary?  I don't see a reason and I don't like it at all.

> Maybe `truncate-lines' has been used because most of the time people
> are more interested in the rule than in the file name.  I also use
> <end> quite often in this buffer to see the filename.  Most of the
> time I only see the directory.

Me too.

> But we can make the *Score Trace* buffer more readable with
> `truncate-lines': We can use `abbreviate-file-name' on the full file
> name and also print the file name (without directory and extension).
> It could look like this:

> ("@my-fqdn>$" 10000 nil r) [my-posts] ->  ~/News/score/topics/my-posts.SCORE

What are »[my-posts]«?

But `abbreviate-file-name' is a good idea IMO.

> Instead of "[", "]" and " -> ", we can use other delimiters: Whatever
> fits well in the new `gnus-score-edit-file-at-point' code and is more
> or clear for the user.

Maybe put these definitions in an alist; use some key and as value a
cons cell with the expansion in the score trace buffer and an approbiate
regexp.

> Additionally, I'd like to add some kind of "Quick help", telling the
> user about useful key bindings in that buffer (and maybe explain the
> output lines above).  See the patch below[1].  Opinions?

IMO a good idea.

Some annotations to the patch; here we have one of the places where
`dolist' is perfectly well suited IMO.  The code then becomes[a] 


If we take the idea of an alist into account we might get[b] 
But that introduces a new variable; maybe the hint in the commentary is
enough.  But the alist is nicer of course.  And if we wanted it to be
perfect we would introduce another variable which holds the
name of key.  Then only one place had to be changed to get another
format.  Very easy with customice.

> Shouldn't this read...

>       (if (or (not file) (string-match "non-file" file) (string= "" file))

> If file is nil, `string-match' will error out otherwise.

Right.  I had that first but changed it I don't know why.

   KP

_____
[a] 
(defun gnus-score-find-trace ()
  "Find all score rules that applies to the current article."
  (interactive)
  (let ((old-scored gnus-newsgroup-scored))
    (let ((gnus-newsgroup-headers
	    (list (gnus-summary-article-header)))
	  gnus-newsgroup-scored trace file)
      (save-excursion
	(nnheader-set-temp-buffer "*Score Trace*"))
      (setq gnus-score-trace nil)
      (gnus-possibly-score-headers 'trace)
      (if (not (setq trace gnus-score-trace))
	  (gnus-error
	   1 "No score rules apply to the current article (default score %d)."
	   gnus-summary-default-score)
	(set-buffer "*Score Trace*")
	;; ToDo: Use a keymap instead?
	(local-set-key "q"
		       (lambda ()
			 (interactive)
			 (bury-buffer nil)
			 (gnus-summary-expand-window)))
	(local-set-key "e" (lambda ()
			     "Run `gnus-score-edit-file-at-point'."
			     (interactive)
			     (gnus-score-edit-file-at-point)))

	(setq truncate-lines t)
	(dolist (entry trace)
	  (setq file (or (car entry)
			 "(non-file rule)"))
	  (insert (format "%S [%s] -> %s\n"
			  ;; sync with `gnus-score-edit-file-at-point'
			  (cdr entry)
			  (file-name-sans-extension
			   (file-name-nondirectory file))
			  (abbreviate-file-name file))))
	(insert
	 "\n\nQuick help:

  q - quit
  e - edit score file entry")
	(goto-char (point-min))
	(gnus-configure-windows 'score-trace)))
    (set-buffer gnus-summary-buffer)
    (setq gnus-newsgroup-scored old-scored)))



[b] 
(defun gnus-score-edit-file-at-point ()
  "Edit score file at point.  Useful especially after `V t'."
  (let* ((rule (save-excursion
		 (beginning-of-line)
		 (read (current-buffer))))
	 (sep "[ \n\r\t]*")
	 (reg (cddr (assq 'newformat gnus-score-trace-format-alist)))
	(file (save-excursion
		;; only works in a Score Trace buffer
		(end-of-line)
		(if (and (re-search-backward reg (point-at-bol) t)
			 (re-search-forward  reg (point-at-eol) t))
		  (buffer-substring (point) (point-at-eol))
		  nil))))
    (if (or (not file) (string-match "non-file" file) (string= "" file))
      (gnus-message 3 "Can't open no file")
      (gnus-score-edit-file file)
      (when  (consp rule)
	;; the rule exists
	(setq rule (mapconcat #'(lambda (obj)
				  (regexp-quote (format "%S" obj)))
			      rule
			      sep))
	(goto-char (point-min))
	(re-search-forward rule nil t)))))


(defun gnus-score-find-trace ()
  "Find all score rules that applies to the current article."
  (interactive)
  (let ((old-scored gnus-newsgroup-scored))
    (let ((gnus-newsgroup-headers
	    (list (gnus-summary-article-header)))
	  (frmt (cadr (assq 'newformat gnus-score-trace-format-alist)))
	  gnus-newsgroup-scored trace file)
      (save-excursion
	(nnheader-set-temp-buffer "*Score Trace*"))
      (setq gnus-score-trace nil)
      (gnus-possibly-score-headers 'trace)
      (if (not (setq trace gnus-score-trace))
	  (gnus-error
	   1 "No score rules apply to the current article (default score %d)."
	   gnus-summary-default-score)
	(set-buffer "*Score Trace*")
	;; ToDo: Use a keymap instead?
	(local-set-key "q"
		       (lambda ()
			 (interactive)
			 (bury-buffer nil)
			 (gnus-summary-expand-window)))
	(local-set-key "e" (lambda ()
			     "Run `gnus-score-edit-file-at-point'."
			     (interactive)
			     (gnus-score-edit-file-at-point)))

	(setq truncate-lines t)
	(dolist (entry trace)
	  (setq file (or (car entry)
			 "(non-file rule)"))
	  (insert (format frmt
			  ;; sync with `gnus-score-edit-file-at-point'
			  (cdr entry)
			  (file-name-sans-extension
			   (file-name-nondirectory file))
			  (abbreviate-file-name file))))
	(insert
	 "\n\nQuick help:

  q - quit
  e - edit score file entry")
	(goto-char (point-min))
	(gnus-configure-windows 'score-trace)))
    (set-buffer gnus-summary-buffer)
    (setq gnus-newsgroup-scored old-scored)))


(defvar gnus-score-trace-format-alist
  (list ;; name            format string     regexp    
   (cons 'newformat (cons "%S [%s] -> %s\n" "-> +"))
   (cons 'oldformat (cons "%S -> %3$s\n"    "-> +"))))



-- 
'Twas brillig, and the slithy toves
    Did gyre and gimble in the wabe;
  All mimsy were the borogoves,
   And the mome raths outgrabe.   "Lewis Carroll" "Jabberwocky"



  reply	other threads:[~2003-12-29 23:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-28 17:45 Karl Pflästerer
2003-12-29 17:15 ` Reiner Steib
2003-12-29 19:59   ` Karl Pflästerer
2003-12-29 21:15     ` Reiner Steib
2003-12-29 23:10       ` Karl Pflästerer [this message]
2003-12-30 13:40         ` Reiner Steib
2003-12-30 17:30           ` Karl Pflästerer
2003-12-30 20:58             ` Reiner Steib
2003-12-30 21:17               ` Karl Pflästerer

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=m3isjzp8z2.fsf@hamster.pflaesterer.de \
    --to=sigurd@12move.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).