13

I know I can set the EDITOR variable and edit my crontab with emacs but that requires starting the process from a shell with

$ crontab -e

My question is how can I directly modify my crontab if I'm inside of emacs already? I tried running starting up eshell and running crontab -e from there but the terminal complains:

$ crontab -e
emacs: Terminal type "dumb" is not powerful enough to run Emacs.
It lacks the ability to position the cursor.
If that is not the actual type of terminal you have,
use the Bourne shell command `TERM=... export TERM' (C-shell:
`setenv TERM ...') to specify the correct type.  It may be necessary
to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.
/usr/bin/crontab: no changes made to crontab

If using crontab in eshell worked that would be a step in the right direction but it's still not exactly what I was hoping for. Attempts to execute crontab -e from within an M-x term buffer in emacs fail as well (at least on OpenBSD 5.6 with emacs 24.3.1). In the ideal case, there would be a crontab mode that allowed me to

M-x crontab

that fires up a major mode and allowed me to do the usual stuff I do at the command line with crontab and have it all bound to keys. I figured for sure there'd be a mode or something for this but I haven't had much luck locating one.

  • There's a crontab-mode in MELPA, did you try it? (I didn't, so I don't know whether it works or whether it does what you want). – wvxvw Mar 17 '15 at 16:01
  • What about using M-x term for launching a not so dumb terminal? – Nsukami _ Mar 17 '15 at 16:02
  • @wvxvw: Yeah I did an M-x list-packages first and found that mode but the description indicates that this is just a highlighting mode that is meant to help the guy who made it work with his personal stuff he keeps under rcs. – unclejamil Mar 17 '15 at 16:06
  • @Nsukami_: That can work but it's not really what I'm after in the end. It keeps me in emacs so it's definitely a step in the right direction and better than leaving emacs but seems like a good mode for crontab is in order (something like M-x crontab) that pulls my crontab and has keys bound to different things I usually do with switches at the command line with crontab. – unclejamil Mar 17 '15 at 16:08
  • @Nsukami_: I've updated the question to clarify what I'm looking for based on our discussion here in the comments. BTW, thank you for the suggestion. – unclejamil Mar 17 '15 at 16:13
20

You could try to use the with-editor package:

(defun crontab-e ()
    "Run `crontab -e' in a emacs buffer."
    (interactive)
    (with-editor-async-shell-command "crontab -e"))

it will run crontab in a subshell, using the current Emacs as editor.

  • Ha! Pretty sweet. Just pulled down the with-editor package and tried it out. Works like a charm! Nice call. I'll wait a day to see if someone has cranked out a full on mode for crontab and if no one comes back with anything I'll mark this as the answer. – unclejamil Mar 17 '15 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.