Last active
February 11, 2021 21:56
-
-
Save chmouel/c8a901ce7739d63854be3bf314bd596a to your computer and use it in GitHub Desktop.
Integrate GNUS with Argos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun gnus-demon-scan-mail-or-news-and-update (level) | |
"Scan for new mail, updating the *Group* buffer." | |
(let ((win (current-window-configuration))) | |
(unwind-protect | |
(save-window-excursion | |
(save-excursion | |
(when (gnus-alive-p) | |
(save-excursion | |
(set-buffer gnus-group-buffer) | |
(gnus-group-get-new-news level))))) | |
(message "scanning for new mail done") | |
(set-window-configuration win)))) | |
(defun gnus-demon-scan-news-and-update () | |
"Scan for new mail, updating the *Group* buffer." | |
(gnus-demon-scan-mail-or-news-and-update 1)) | |
;;; ** command | |
(gnus-demon-add-handler 'gnus-demon-scan-news-and-update 1 nil) | |
(gnus-demon-add-handler 'gnus-demon-scan-mail 1 nil) | |
(gnus-demon-init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Export the unread inbox as json to plug into external command line | |
;; emacsclient --eval "(my-is-there-any-mail-out-there-json)"|sed -e \ | |
;; 's/^"//;s/"$//' -e 's/\\"/"/g'|jq | |
(defconst my-is-there-any-mail-out-there-limit-to ".*") | |
(defun my-is-there-any-mail-out-there-json () | |
(let ((win (current-window-configuration)) | |
(hashtb (make-hash-table :size 10 :test #'equal)) | |
unread current) | |
(unwind-protect | |
(save-window-excursion | |
(when (gnus-alive-p) | |
(with-current-buffer gnus-group-buffer | |
(beginning-of-buffer) | |
(while (and (not (eobp))) | |
(beginning-of-line) | |
(when (and | |
(get-text-property (point) 'gnus-group) | |
(string-match | |
my-is-there-any-mail-out-there-limit-to | |
(gnus-group-name-at-point))) | |
(setq unread (get-text-property (point) 'gnus-unread)) | |
(when (and (numberp unread) (> unread 0)) | |
(puthash (gnus-group-name-at-point) unread hashtb))) | |
(forward-line))))) | |
(set-window-configuration win)) | |
(json-serialize hashtb))) | |
(defun my-is-there-any-mail-out-there-focus-group (group-regexp) | |
(let ((win (current-window-configuration)) | |
found) | |
(unwind-protect | |
(save-window-excursion | |
(save-excursion | |
(when (gnus-alive-p) | |
(save-excursion | |
(set-buffer gnus-group-buffer) | |
(goto-char (point-min)) | |
(when (re-search-forward group-regexp) | |
(setq found (point)) | |
)))))) | |
(if found (progn | |
(switch-to-buffer gnus-group-buffer) | |
(goto-char found) | |
(gnus-group-select-group)) | |
(set-window-configuration win)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import os | |
import re | |
import subprocess | |
import sys | |
notify_me_on_inbox = re.compile("INBOX") | |
only_show_inbox = re.compile(r".*") | |
remove_gmail_folder = True | |
def get_inbox_statuses(): | |
try: | |
emacsclient_output = subprocess.run( | |
"emacsclient --eval \"(my-is-there-any-mail-out-there-json)\"", | |
stderr=subprocess.PIPE, | |
shell=True, | |
check=True, | |
stdout=subprocess.PIPE) | |
except subprocess.CalledProcessError: | |
return {} | |
return json.loads( | |
(emacsclient_output.stdout.decode()[1:-2].replace('\\"', '"'))) | |
def main(): | |
jeez = get_inbox_statuses() | |
meself = os.path.realpath(__file__) | |
if not jeez: | |
print("⬛") | |
return | |
icon = "📪" | |
ret = ["---"] | |
for inbox, number in jeez.items(): | |
if remove_gmail_folder: | |
inbox = inbox.split("/")[-1] | |
if not only_show_inbox.match(inbox): | |
continue | |
if notify_me_on_inbox.match(inbox): | |
icon = "💌" | |
ret.append( | |
f"{inbox} ({number}) | bash=\"{meself} {inbox}\" terminal=false") | |
if len(ret) == 1: | |
print("⬛") | |
return | |
ret.insert(0, f"{icon}") | |
print("\n".join(ret)) | |
def goto_inbox(inbox): | |
subprocess.run( | |
f"emacsclient --eval '(my-is-there-any-mail-out-there-focus-group \"{inbox}\")'", | |
stderr=subprocess.PIPE, | |
shell=True, | |
check=True, | |
stdout=subprocess.PIPE) | |
# TO be able to focus the emacs windows get something like jumpapp https://github.com/mkropat/jumpapp | |
subprocess.run("jumpapp emacs27", | |
stderr=subprocess.PIPE, | |
shell=True, | |
check=True, | |
stdout=subprocess.PIPE) | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
try: | |
goto_inbox(sys.argv[1]) | |
except subprocess.CalledProcessError: | |
pass | |
else: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will show a icon in gnome for all your gnus groups.
~/.config/argos
You don't have necessary need to use the gnome argos stuff you can plug it in anything you want, you can just get the json output from the emacsclient, i.e: :