reddit / emacs

Need to block distractions (like email, RSS, etc)? Announcing time-block-command, a configurable command blocker using block groups.

sierrawhiskeyfoxtrot · 2022-08-06 17:39
elimik31 · 2022-08-08 11:31
I needed this, thanks, I'll give this a look! Combatting emacs-procrastination is tricky since it's the same tool I use for work and there's not really much of a context switch when going from working with emacs to procrastinating with emacs. Have you thought about using emacs [advices](https://emacsdocs.org/docs/elisp/Advising-Named-Functions#macro-define-advice-symbol-where-lambda-list-optional-name-depth-rest-body)? The simplest would be to just override the original commands with the time-blocked versions, e.g. after your example from the readme (advice-add 'elfeed :override #'my/start-elfeed) Would result in the `elfeed` function always running the time-blocked version. But I can imagine one could use an `:around` or another non-overriding advice for creating a time-blocked function. And using this I could imagine implementing an `add-time-blocking-advice` as an alternative to `define-time-blocked-command` which just takes a function as an argument and adds all the rest itself.
sierrawhiskeyfoxtrot · 2022-08-08 14:01
That's exactly the reason I built this! It really makes it tough to deal with. After I posted this, I had started thinking about using and `:around` advice based mechanism for simpler ones (`elfeed`, for instance). However, I need to figure out how to get lambda lists to do it well (I think).
sierrawhiskeyfoxtrot · 2022-08-08 14:39
Well, I just sat down and wrote a bit to use around advice. I'd love to hear your feedback on it.
elimik31 · 2022-08-08 17:42
Feedback: I didn't try it when writing the above comment as I was busy, but I now gave it a try and installed it, luckily easy with `use-package` + `straight`. However, when I justed tested it with the elfeed advise from the example, I got the following error: Debugger entered--Lisp error: (void-function rest) rest((workday (1 ("09:00" . "20:00")) (2 ("09:00" . "17:00")) (3 ("09:00" . "17:00")) (4 ("09:00" . "17:00")) (5 ("09:00" . "17:00")))) time-block-group-blocked-p(workday) (and (time-block-group-blocked-p 'workday) (not (yes-or-no-p "You have decided not to check news currently.\nStil..."))) (if (and (time-block-group-blocked-p 'workday) (not (yes-or-no-p "You have decided not to check news currently.\nStil..."))) (message "You have decided not to check news currently.") (if (called-interactively-p) (call-interactively orig) (apply orig args))) my/elfeed-block-advice(#f(advice ad-Advice-elfeed :around #f(compiled-function () (interactive nil) #<bytecode -0x1876f779b432bf20>))) apply(my/elfeed-block-advice #f(advice ad-Advice-elfeed :around #f(compiled-function () (interactive nil) #<bytecode -0x1876f779b432bf20>)) nil) elfeed() funcall-interactively(elfeed) command-execute(elfeed record) execute-extended-command(nil "elfeed" #("elf" 0 3 (ws-butler-chg chg))) funcall-interactively(execute-extended-command nil "elfeed" #("elf" 0 3 (ws-butler-chg chg))) command-execute(execute-extended-command) Seems emacs tries to execute `rest` as a function, but I assume it's taken from some `&rest arguments` or something like that. Also, I took a quick look in the code. But to be honest I'm far from an emacs magician, most of my emacs lisp is just simple function in my own `init.el`, so I was a bit intimidated by the macros, as I've not used them much myself. Not sure if it's somehow possible to avoid them. Would be easily possible with a lambda, but then you wouldn't have a named advice and this is something I assume you don't want. But I'm not good enough at emacs lisp to give the answer myself.
sierrawhiskeyfoxtrot · 2022-08-08 19:03
What is your configuration (`time-block-groups`, relevant call to `time-block-advise`? The call to `rest` there *should* be valid, `rest` is an alias of `cdr`. What happens with `M-: (message "%S" (time-block-group-blocked-p 'workday)) RET` on its own? `M-: (message "%S" (rest '(1 2 3 4 5))) RET`? *Edit:* I've added a `(require 'cl-lib)` to the top of the package. That *should* fix it.
elimik31 · 2022-08-08 20:38
`cl-lib` contains the functions `cl-rest`, which does what you want. `rest` is contained in the obsolete `cl` library, so I get it to work with `(require 'cl)`, but with a warning that it's obsolete, in particular `rest` is in the list of functions obsolete since emacs 27.1, (see [here](https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/obsolete/cl.el#n270)).
sierrawhiskeyfoxtrot · 2022-08-08 21:12
I still periodically write in common lisp, so I frequently forget to prefix with `cl-`, and byte compilation doesn't seem to warn for all of them.