How to make Emacs Gnus to get new mails automatically? - email

I try to fetch new mails with Gnus, but it doesn't work. I tried following options in my .emacs file:
;(setq gnus-demon-timestep 10)
(gnus-demon-add-handler 'gnus-group-get-new-news 1 nil)
;(gnus-demon-add-handler 'gnus-demon-scan-mail 1 nil)
;(gnus-demon-add-handler 'gnus-demon-scan-news 1 nil)
(gnus-demon-init)
I tried to add each of the 3 handlers, and put t instead of nil, but it didn't work. If I press g or run M-x gnus-group-get-new-news manually Gnus does fetchs new mails. I checked gnus-demon-handlers and it indeed says: gnus-demon-handlers's value is ((gnus-group-get-new-news 1 nil)) but it doesn't fetch mails automatically.

Try moving (gnus-demon-init) above the rest. The functions don't exist until that the demon is initialized.
e.g.
(add-hook 'gnus-startup-hook
'(lambda ()
(gnus-demon-init)
(setq gnus-demon-timestep 60) ;; each timestep is 60 seconds
;; Check for new mail every 1 timestep (1 minute)
(gnus-demon-add-handler 'gnus-demon-scan-news 1 t)
;; Don't crash gnus if disconnected
(defadvice gnus-demon-scan-news (around gnus-demon-timeout activate)
"Timeout for Gnus."
(with-timeout
(120 (message "Gnus timed out."))
ad-do-it))))

Related

Bulk reschedule org agenda items preserving date

I sometimes forget to do one or more of my daily habits that happen at the same time each day and need to bring them current so I can get orgzly notifications of them.
I am able to shift a single item in org agenda preserving the date with M-x org-agenda-date-later and it reschedules that to the current date with whatever time existed.
If I try to use it as a bulk action by marking an item and doing B f org-agenda-date-later I get:
Debugger entered--Lisp error: (wrong-number-of-arguments #f(compiled-function (arg &optional what) (interactive "p") #<bytecode 0x1ad5eed>) 0)
org-agenda-date-later()
org-agenda-bulk-action(nil)
funcall-interactively(org-agenda-bulk-action nil)
call-interactively(org-agenda-bulk-action nil nil)
command-execute(org-agenda-bulk-action)
This tells me that org-agenda-date-later wasn't written to be used as a bulk action. One solution for this could be writing a bulk action that calls org-agenda-date-later multiple times but I do not know how to do that.
I searched for other solutions and I found something recommended by the author of org mode from the org mode FAQ:
(defun org-agenda-reschedule-to-today ()
(interactive)
(flet ((org-read-date (&rest rest) (current-time)))
(call-interactively 'org-agenda-schedule)))
This works as a bulk action but it loses the time the item was scheduled. That means I would have to go through my habits and reschedule the time for each one after doing this which is inconvenient.
There is the org-agenda-bulk-custom-functions to which you can add a key-binding and an associated function. So, for example, adding a binding for D after calling org-agenda-bulk-action, you could use
(setq org-agenda-bulk-custom-functions
`((?D (lambda () (call-interactively 'org-agenda-date-later)))
,#org-agenda-bulk-custom-functions))
It will pass the prefix on, allowing C-u -1 B D to reshedule the tasks a day earlier at the same time, for example.

Insert current entry into BBDB

I've read that "The easiest way to insert an entry for a person into BBDB is to press : (colon) in the Summary buffer when a message from him is the selected one. If the person is in the database already, nothing happens; otherwise, Emacs asks you if you want to insert him into the database."
That does not work for me, I guess because I'm using BBDB 3.
EDIT: ':' runs the command 'bbdb-mua-display-sender'.
Is there a workaround to this?
This is what I use in my .emacs to work with BBDB-3 in Gnus, it will give this functionality to the ; key:
(require 'bbdb-autoloads)
(require 'bbdb)
;; initialization
(bbdb-initialize 'gnus 'message)
(bbdb-mua-auto-update-init 'gnus 'message)
;; size of the bbdb popup
(setq bbdb-pop-up-window-size 0.15)
(setq bbdb-mua-pop-up-window-size 0.15)
;; What do we do when invoking bbdb interactively
(setq bbdb-mua-update-interactive-p '(query . create))
;; Make sure we look at every address in a message and not only the
;; first one
(setq bbdb-message-all-addresses t)
;; use ; on a message to invoke bbdb interactively
(add-hook
'gnus-summary-mode-hook
(lambda ()
(define-key gnus-summary-mode-map (kbd ";") 'bbdb-mua-edit-field)))
I got this information from somewhere on the net, but can't quite locate where just now; maybe this can set you on the correct path?

Default Archive Group in Gnus

I am using the following code to archive replies to messages in the same group they come from; it works well.
;; Store sent messages in the same group they came from
(setq gnus-message-archive-method '(nnml ""))
(setq gnus-message-archive-group
'((lambda (x)
(cond
;; Store personal mail messages in the same group I started out in
((string-match ".*" group) group)
;; Store everything else in misc until I can sort it out
(t "mail.misc")))))
However, if I use C-x m from a non-GNUs buffer, or create a message without a group selected, there seems to be no archiving at all; the message is lost unless I manually fill in a GCC: mail.misc line. How can I make this happen automatically for all messages not made from within a group?
First you have to set gnus as mail handler.
(setq mail-user-agent 'gnus-user-agent)
Still this doesn't work, if gnus is not running when starting to
write a mail with C-x m. Here a advice helps.
(defadvice gnus-msg-mail (before start-gnus activate)
(require 'gnus-start)
(unless (gnus-alive-p)
(save-window-excursion
(let ((inhibit-redisplay t))
(gnus)))))

How to automatically do org-mobile-push org-mobile pull in emacs

Since I am using org-mode to track my todo list in emacs, I like the iPhone app: MobileOrg, with it, I can access my todo list all day.
But here's the problem:
I have to manually org-mobile-push my changes from local file to mobile phone through dropbox, and org-mobile-pull the changes made by phone back.
How to make that automatically? Like adding some recipes in dotemacs file.
Add these two lines to dot emacs file:
(add-hook 'after-init-hook 'org-mobile-pull)
(add-hook 'kill-emacs-hook 'org-mobile-push)
With them, it automatically pulls the changes on emacs startup, and pushes the changes before emacs exits.
-- Update
If you never exit your Emacs, this solution might not work for you. So, another solution using idle timer
;; moble sync
(defvar org-mobile-sync-timer nil)
(defvar org-mobile-sync-idle-secs (* 60 10))
(defun org-mobile-sync ()
(interactive)
(org-mobile-pull)
(org-mobile-push))
(defun org-mobile-sync-enable ()
"enable mobile org idle sync"
(interactive)
(setq org-mobile-sync-timer
(run-with-idle-timer org-mobile-sync-idle-secs t
'org-mobile-sync)));
(defun org-mobile-sync-disable ()
"disable mobile org idle sync"
(interactive)
(cancel-timer org-mobile-sync-timer))
(org-mobile-sync-enable)
I just found out it is same as below answer, so, if you prefer the idle timer solution, please upvote tkf's answer.
I have something like this in my Emacs setting to do push and pull when I am away from computer.
(defvar my-org-mobile-sync-timer nil)
(defvar my-org-mobile-sync-secs (* 60 20))
(defun my-org-mobile-sync-pull-and-push ()
(org-mobile-pull)
(org-mobile-push)
(when (fboundp 'sauron-add-event)
(sauron-add-event 'my 3 "Called org-mobile-pull and org-mobile-push")))
(defun my-org-mobile-sync-start ()
"Start automated `org-mobile-push'"
(interactive)
(setq my-org-mobile-sync-timer
(run-with-idle-timer my-org-mobile-sync-secs t
'my-org-mobile-sync-pull-and-push)))
(defun my-org-mobile-sync-stop ()
"Stop automated `org-mobile-push'"
(interactive)
(cancel-timer my-org-mobile-sync-timer))
(my-org-mobile-sync-start)
Alternative is to put the following in cron job
(I found this here https://github.com/matburt/mobileorg-android/wiki/Scripting/):
emacs --batch --load ~/.emacs --eval "(org-mobile-pull)" --eval "(org-mobile-push)"
This code is taken from http://kenmankoff.com/2012/08/17/emacs-org-mode-and-mobileorg-auto-sync/, with a couple of details changed. You need to configure the variables in the beginning. This code will
Check every 30s whether MobileOrg has synced, and if so
Pull from MobileOrg.
Push to MobileOrg.
This is necessary to update the agenda views in MobileOrg.
With this behavior, you can be away from your computer, update some things in MobileOrg, sync, wait 30 seconds, sync again, and your mobile agenda view will be updated.
Whenever an org file is saved
Check whether the saved org file is supposed to be synced with MobileOrg, and if so
Wait for the user to become idle
Push to MobileOrg
Code for your .emacs file:
(require 'org-mobile)
;; Configure these two variables
(setq org-mobile-inbox-for-pull "~/Dropbox/org/mobile.org"
org-mobile-directory "~/Dropbox/MobileOrg")
(require 'gnus-async)
;; Define a timer variable
(defvar org-mobile-push-timer nil
"Timer that `org-mobile-push-timer' used to reschedule itself, or nil.")
;; Push to mobile when the idle timer runs out
(defun org-mobile-push-with-delay (secs)
(when org-mobile-push-timer
(cancel-timer org-mobile-push-timer))
(setq org-mobile-push-timer
(run-with-idle-timer
(* 1 secs) nil 'org-mobile-push)))
;; After saving files, start an idle timer after which we are going to push
(add-hook 'after-save-hook
(lambda ()
(if (or (eq major-mode 'org-mode) (eq major-mode 'org-agenda-mode))
(dolist (file (org-mobile-files-alist))
(if (string= (expand-file-name (car file)) (buffer-file-name))
(org-mobile-push-with-delay 10))))))
;; watch mobileorg.org for changes, and then call org-mobile-pull
(defun org-mobile-install-monitor (file secs)
(run-with-timer
0 secs
(lambda (f p)
(unless (< p (second (time-since (elt (file-attributes f) 5))))
(org-mobile-pull)
(org-mobile-push)))
file secs))
(defvar monitor-timer (org-mobile-install-monitor (concat org-mobile-directory "/mobileorg.org") 30)
"Check if file changed every 30 s.")
you can also push right after saving a note, like this:
(add-hook
'after-save-hook
(lambda ()
(if (string= buffer-file-name "<path to my notes.org>")
(org-mobile-push)
)
))
I use this elisp code from gist on my init.el and it works pretty well, except it doesn't have org-mobile-pull built in.
As a side solution, similar to Sandeep C's
;; for Emacs 24.3.1 insert next line
(require 'cl)
;; automatically org-mobile-push on save of a file
(add-hook
'after-save-hook
(lambda ()
(let (
(org-filenames (mapcar 'file-name-nondirectory (directory-files org-directory))) ; list of org file names (not paths)
(filename (file-name-nondirectory buffer-file-name)) ; list of the buffers filename (not path)
)
(if (find filename org-filenames :test #'string=)
(org-mobile-push)
)
)
)
)
I opted to simply push when saving, so I added this to my emacs init file:
(defun org-mobile-push-on-save ()
"Used in `after-save-hook'."
(when (memq this-command '(save-buffer save-some-buffers))
(org-mobile-push)))
(add-hook 'org-mode-hook
(lambda ()
(add-hook 'after-save-hook 'org-mobile-push-on-save nil 'make-local)))
In a nutshell, it adds an after-save-hook to org-mode buffers.
More info on the code:
https://emacs.stackexchange.com/a/14476/12694
https://stackoverflow.com/a/6141681/45881
For auto-pull, a timer as in other answers is probably a good way.

Tracking down max-specpdl-size errors in emacs

I've been randomly getting the following error in emacs:
Variable binding depth exceeds max-specpdl-size
...and I've been getting it at very random moments. After researching this, it seems as though some elisp somewhere is recursing too deeply. Are there any strategies for tracking this down? I'm totally at a loss as far as what is actually causing this.
I've gotten some errors indicating something along the lines of infinite recursion with ropemacs (but these are usually Python errors). Could something be misconfigured with ropemacs?
Update: Interestingly enough, I've found that I always get this error if I do a "C-h a" for "speedbar" but not for "rope-".
To track the problem down, you can try this:
(setq max-specpdl-size 5) ; default is 1000, reduce the backtrace level
(setq debug-on-error t) ; now you should get a backtrace
C-h a ; in speedbar
You should get a backtrace upon the error, and at that point, you can track down the offending routine.
I'd also try loading emacs w/out your configuration file (emacs -q), to see if there's something in your .emacs that is affecting things. (I don't get the infinite loop using C-h a). And if it is your .emacs, then the best way I've found to track that down is either binary search (put an error (error "frog") or somesuch in the middle of your .emacs, load, test, if no problems, put the error at 3/4, otherwise at 1/4, repeat...), or manually evaluate your .emacs line by line (region by region), testing after each portion. Those settings should help.
For me too it did not work. I found with C-h+v that actually max-specpdl-size was not changed to 5 at all by the setq. I then tried to set it interactively with M-x set-variable. That too did not change its value. Finally I managed to set it with M-x customize-variable.
Btw, on my system max-specpdl-size was 140 and thus to small. I had to increase it to 1000, not in order to get a backtrace and debug it, but to make it work.
The kind of bug still exists 10 years after the report, in XEmacs 21.4 (patch 24) "Standard C" [Lucid] (x86_64-linux-gnu, Mule). I get it from M-x vm (trying to read my e-mail, which I do many times every day).
Debugger entered--Lisp error: (error "Variable binding depth exceeds max-specpdl-size")
signal(error ("Variable binding depth exceeds max-specpdl-size"))
byte-code("..." [buf data kill-buffer signal] 3)
find-file-noselect("/home/brech/mail/folders/INBOX")
byte-code("..." [f full-startup access-method remote-spec buffer-file-coding-system folder string-match imap pop bufferp nil vm-pop-find-spec-for-name error "No such POP folder: %s" vm-pop-make-filename-for-spec t file-exists-p (rename-file f-pass f-nospec) ((error)) (rename-file f-nopass f-nospec) ((error)) 3 vm-imap-parse-spec-to-list vm-imap-make-filename-for-spec expand-file-name file-directory-p "%s is a directory" vm-get-file-buffer no-conversion raw-text message "Reading %s..." find-file-noselect "Reading %s... done" (pop imap) buffer-name rename-buffer set-buffer-multibyte get-coding-system no-conversion-unix no-conversion-dos no-conversion-mac binary buffer-modified-p ((set-buffer-modified-p omodified)) encode-coding-region set-buffer-file-coding-system decode-coding-region coding-system-base raw-text-unix ...] 9)
ad-Orig-vm(nil nil nil)
(setq ad-return-value (ad-Orig-vm folder read-only access-method))
(let (ad-return-value) (if (and ... mail-archive-file-name folder ... ...) (setq read-only ...)) (setq ad-return-value (ad-Orig-vm folder read-only access-method)) ad-return-value)
(lambda (&optional folder read-only access-method) "$ad-doc: vm$" (interactive (list nil current-prefix-arg)) (let (ad-return-value) (if ... ...) (setq ad-return-value ...) ad-return-value))(nil nil)
call-interactively(vm)
command-execute(vm t)
execute-extended-command(nil)
call-interactively(execute-extended-command)
A crude work-around is quitting XEmacs and starting all over. Only quitting and re-starting vm does not help.