Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* Re: New articles since last viewing via gnus-group-line-format?
       [not found] <87d1oasj1h.fsf@b79.net>
@ 2016-06-08  4:48 ` John Magolske
  2016-06-30 16:33   ` Dmitry Alexandrov
  0 siblings, 1 reply; 2+ messages in thread
From: John Magolske @ 2016-06-08  4:48 UTC (permalink / raw)
  To: info-gnus-english

Think I found a solution to this...

John Magolske <listmail@b79.net> writes:
> I'd like to have a mark show up next to each group in the Gnus group
> buffer to signify whether or not new articles have arrived since the
> last viewing of that group (similar to Mutt's "N if folder has new
> mail, blank otherwise"). I see there's %m in gnus-group-line-format:
>
>     %m  Whether there is new(ish) mail in the group (char, "%")
>
> which should place by default a %, or other character as defined by the
> gnus-new-mail-mark variable. So I put a %m in my gnus-group-line-format:
>
>     (setq gnus-group-line-format "%P%m %M%S%p%5,5y/%-5,5t :%*%B%-60,60ug%ud\n")
>  
> ..but I'm not seeing the % mark in the group buffer next to groups that
> have new email.

I put together the following elisp, which seems to be doing what I want.
Upon exiting a group, the number of unread articles is recorded as a
parameter. Then, the function gnus-user-format-function-N compares that
against the current total number of unread articles. If the current
number is greater, an N is displayed via gnus-group-line-format. I
*think* this is working properly... any suggestions for improvements or
alternate approaches are welcome. One thing that is required for this to
work is for every group to be initially entered/exited at least once.

;; Used gnus-group-set-timestamp as an example when writing this:
(defun gnus-group-record-unread-count ()
  "record the number of unread messages in a group, can be used in hooks like `gnus-select-group-hook'or `gnus-group-catchup-group-hook'."
    (when gnus-newsgroup-name
      (let ((lastcount (gnus-group-unread gnus-newsgroup-name)))
        (gnus-group-set-parameter gnus-newsgroup-name 'prev-unread-count lastcount))))

;; used gnus-group-timestamp as an example when writing this this:
(defsubst gnus-group-recall-prev-unread-count (group)
  "return the value of the number of unread messages in GROUP"
  (gnus-group-get-parameter group 'prev-unread-count t))

;; record number of unread messages in a group when exiting that group
(add-hook 'gnus-summary-exit-hook
          (lambda ()
          (gnus-group-record-unread-count)
          (gnus-group-update-group-line)))

;; For use in gnus-group-line-format, displays "N" if there are more unread
;; messages in a group currently than the last time that group was entered
(defun gnus-user-format-function-N (headers)
  (let ((prev-count (gnus-group-recall-prev-unread-count gnus-tmp-group))
        (cur-count (gnus-group-unread gnus-tmp-group)))
    (if prev-count
        (if cur-count
            (if (< prev-count cur-count)
                (message "N")
              (message " ")))
      (message "~")))) ; a ~ here shows up groups that've never been entered/exited

;; Then place a %uN in the gnus-group-line-format :
(setq gnus-group-line-format "%P%uN %M%S%p%5,5y/%-5,5t :%*%B%-60,60ug%ud\n")


The following functions will download email / news and update the
group-line-format in the group buffer. In conjunction with the above
elisp, this places an N in front of groups that have new articles. I'm
using fdm to download email into ~/Mail and the nnfolder backend to
access this with Gnus. For news I use slrnpull to pull articles into
~/News and read from that local spool using the nnspool backend.

;; Update groups under the topic named "Email". A modification of
;; gnus-topic-get-new-news-this-topic, I found this necessary
;; as gnus-group-get-new-news by itself doesn't "Get" newly arrived
;; articles for my nnfolder email
(defun gnus-group-get-email ()
  (interactive)
  "Check for new news in the \"Email\" topic."
  (let* ((topic "Email")
         (data (cadr (gnus-topic-find-topology topic))))
    (save-excursion
      (gnus-topic-mark-topic topic nil)
      (gnus-group-get-new-news-this-group))
    (gnus-topic-remove-topic (eq 'visible (cadr data)))))

;; get email
(defun gnus-download-email ()
  (interactive)
  (shell-command "fdm -f ~/path-to-fdm.conf -m -a account_1 -a account_2 fetch")
  (gnus-group-get-email))
(define-key gnus-group-mode-map (kbd "Ge") 'gnus-download-email)

;; get news
(defun gnus-download-news ()
  (interactive)
  (shell-command "~/bin/slrnp") ; slrnp is a script that runs slrnpull against several accounts
  (gnus-group-get-new-news))
(define-key gnus-group-mode-map (kbd "Gn") 'gnus-download-news)


I find having a flag to notify the arrival of new articles since the
last viewing of a group very useful. Displaying the number of unread
articles by itself I don't find all that helpful, as I won't necessarily
remember how many unread messages were present at the last viewing of a
group. And I don't want to always mark all articles in a group as read,
as I might read a few articles in a thread and decide to re-visit it
later picking up where I left off, etc.


-- 
John Magolske
http://b79.net/contact

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

* Re: New articles since last viewing via gnus-group-line-format?
  2016-06-08  4:48 ` New articles since last viewing via gnus-group-line-format? John Magolske
@ 2016-06-30 16:33   ` Dmitry Alexandrov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Alexandrov @ 2016-06-30 16:33 UTC (permalink / raw)
  To: John Magolske; +Cc: info-gnus-english

John Magolske <trimtab@b79.net> writes:

> Think I found a solution to this...
>
> John Magolske <listmail@b79.net> writes:
>> I'd like to have a mark show up next to each group in the Gnus group
>> buffer to signify whether or not new articles have arrived since the
>> last viewing of that group (similar to Mutt's "N if folder has new
>> mail, blank otherwise"). I see there's %m in gnus-group-line-format:
>>
>>     %m  Whether there is new(ish) mail in the group (char, "%")
>>
>> which should place by default a %, or other character as defined by the
>> gnus-new-mail-mark variable. So I put a %m in my gnus-group-line-format:
>>
>>     (setq gnus-group-line-format "%P%m %M%S%p%5,5y/%-5,5t :%*%B%-60,60ug%ud\n")
>>
>> ..but I'm not seeing the % mark in the group buffer next to groups that
>> have new email.
>
> I put together the following elisp, which seems to be doing what I want.
> Upon exiting a group, the number of unread articles is recorded as a
> parameter. Then, the function gnus-user-format-function-N compares that
> against the current total number of unread articles. If the current
> number is greater, an N is displayed via gnus-group-line-format. I
> *think* this is working properly... any suggestions for improvements or
> alternate approaches are welcome. One thing that is required for this to
> work is for every group to be initially entered/exited at least once.
>
> ;; Used gnus-group-set-timestamp as an example when writing this:
> (defun gnus-group-record-unread-count ()
>   "record the number of unread messages in a group, can be used in hooks like `gnus-select-group-hook'or `gnus-group-catchup-group-hook'."
>     (when gnus-newsgroup-name
>       (let ((lastcount (gnus-group-unread gnus-newsgroup-name)))
>         (gnus-group-set-parameter gnus-newsgroup-name 'prev-unread-count lastcount))))
>
> ;; used gnus-group-timestamp as an example when writing this this:
> (defsubst gnus-group-recall-prev-unread-count (group)
>   "return the value of the number of unread messages in GROUP"
>   (gnus-group-get-parameter group 'prev-unread-count t))
>
> ;; record number of unread messages in a group when exiting that group
> (add-hook 'gnus-summary-exit-hook
>           (lambda ()
>           (gnus-group-record-unread-count)
>           (gnus-group-update-group-line)))
>
> ;; For use in gnus-group-line-format, displays "N" if there are more unread
> ;; messages in a group currently than the last time that group was entered
> (defun gnus-user-format-function-N (headers)
>   (let ((prev-count (gnus-group-recall-prev-unread-count gnus-tmp-group))
>         (cur-count (gnus-group-unread gnus-tmp-group)))
>     (if prev-count
>         (if cur-count
>             (if (< prev-count cur-count)
>                 (message "N")
>               (message " ")))
>       (message "~")))) ; a ~ here shows up groups that've never been entered/exited
>
> ;; Then place a %uN in the gnus-group-line-format :
> (setq gnus-group-line-format "%P%uN %M%S%p%5,5y/%-5,5t :%*%B%-60,60ug%ud\n")
>
> <...>
>
> I find having a flag to notify the arrival of new articles since the
> last viewing of a group very useful. Displaying the number of unread
> articles by itself I don't find all that helpful, as I won't necessarily
> remember how many unread messages were present at the last viewing of a
> group. And I don't want to always mark all articles in a group as read,
> as I might read a few articles in a thread and decide to re-visit it
> later picking up where I left off, etc.

Many thanks, I’ll take this as an example of writing user line formats.
But why built-in ‘%U Number of unseen articles (integer)’ did not
satisfy your needs, I wonder.

_______________________________________________
info-gnus-english mailing list
info-gnus-english@gnu.org
https://lists.gnu.org/mailman/listinfo/info-gnus-english

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

end of thread, other threads:[~2016-06-30 16:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87d1oasj1h.fsf@b79.net>
2016-06-08  4:48 ` New articles since last viewing via gnus-group-line-format? John Magolske
2016-06-30 16:33   ` Dmitry Alexandrov

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