Fixed issues with my focus mode

This commit is contained in:
Howard Abrams 2024-10-25 16:21:49 -07:00
parent de7770280a
commit 4629cbf1a0
4 changed files with 42 additions and 21 deletions

View file

@ -1,13 +1,18 @@
;;; ha-focus.el --- Emacs lisp code to focus my thoughts. -*- lexical-binding: t; -*- ;;; ha-focus.el --- Emacs lisp code to focus my thoughts. -*- lexical-binding: t; -*-
;; ;;
;; Copyright (C) 2021 Howard X. Abrams ;; Copyright © 2021,2024 Howard X. Abrams
;; ;;
;; Author: Howard X. Abrams <http://gitlab.com/howardabrams> ;; Author: Howard X. Abrams <http://gitlab.com/howardabrams>
;; Maintainer: Howard X. Abrams <howard.abrams@workday.com> ;; Maintainer: Howard X. Abrams <howard.abrams@gmail.com>
;; Created: May 28, 2021 ;; Created: May 28, 2021
;; ;;
;; This file is not part of GNU Emacs. ;; This file is not part of GNU Emacs.
;; ;;
;;; Commentary:
;;
;; Find details of this code on my website at:
;; https://www.howardism.org/Technical/Emacs/focused-work.html
;;
;; *NB:* Do not edit this file. Instead, edit the original literate file at: ;; *NB:* Do not edit this file. Instead, edit the original literate file at:
;; ~/website/Technical/Emacs/focused-work.org ;; ~/website/Technical/Emacs/focused-work.org
;; And tangle the file to recreate this one. ;; And tangle the file to recreate this one.
@ -18,7 +23,7 @@
(defun ha-focus-countdown-timer (minutes fun) (defun ha-focus-countdown-timer (minutes fun)
(let ((the-future (* minutes 60))) (let ((the-future (* minutes 60)))
(run-at-time the-future nil fun))) (setq ha-focus-timer (run-at-time the-future nil fun))))
(defun ha-focus-begin () (defun ha-focus-begin ()
"Start a concerted, focused effort, ala Pomodoro Technique. "Start a concerted, focused effort, ala Pomodoro Technique.
@ -31,44 +36,57 @@ Call `ha-focus-break' when finished."
(ha-focus--command "tell application \"Spotify\" to play") (ha-focus--command "tell application \"Spotify\" to play")
(if (eq major-mode 'org-mode) (if (eq major-mode 'org-mode)
(org-clock-in) (org-clock-in)
(org-clock-in-last))) (org-clock-in-last))
(message "🍅 Started clocked %s"
(substring-no-properties
(org-clock-get-clock-string))))
(defun ha-focus-break () (defun ha-focus-break ()
"Stop the focused time by stopping the music. "Stop the focused time by stopping the music.
This also starts another break timer, that calls This also starts another break timer, that calls
`ha-focus-break-over' when finished." `ha-focus-break-over' when finished."
(interactive) (interactive)
(run-with-idle-timer 5 nil 'ha-focus-capture) (run-with-idle-timer 30 nil 'ha-focus-capture)
(ha-focus--command "tell application \"Spotify\" to pause") (ha-focus--command "tell application \"Spotify\" to pause")
(message "Time to take a break.")) (ha-focus-countdown-timer 5 'ha-focus-break-over)
(message "🍅 Time to take a break."))
(defun ha-focus-capture () (defun ha-focus-capture ()
"Spin up a capture window."
(ignore-errors (ignore-errors
(org-capture nil "cc") (org-capture nil "cc")
(sit-for 1) (sit-for 1)
(org-clock-out)) (org-clock-out)))
(ha-focus-countdown-timer 5 'ha-focus-break-over)
(message "Taking a much needed break..."))
(defun ha-focus-break-over () (defun ha-focus-break-over ()
"Message me to know that the break time is over. Notice that "Message me to know that the break time is over. Notice that
this doesn't start anything automatically, as I may have simply this doesn't start anything automatically, as I may have
wandered off." wandered off."
(ha-focus--command "set v to output volume of (get volume settings) (ha-focus--command "set v to output volume of (get volume settings)
set volume output volume 1 set volume output volume 1
say \"Break time over. Back on your head.\" say \"Break time over. Back on your head.\"
set volume output volume v")) set volume output volume v")
(message "🍅 Type <f12> to restart the timer."))
(defun ha-focus-interrupt ()
"Interrupt the current focused timer, if set."
(interactive)
(when (timerp ha-focus-timer)
(cancel-timer ha-focus-timer)
(ignore-errors
(org-clock-out))))
(require 'async)
(defun ha-focus--command (osascript) (defun ha-focus--command (osascript)
"Runs OSASCRIPT by passing to the `osascript' command asynchronously." "Runs OSASCRIPT by passing to the `osascript' command asynchronously."
(async-start-process "focus-os" "osascript" 'ha-focus--command-callback "-e" osascript)) (async-start-process "focus-os" "osascript"
'ha-focus--command-callback "-e" osascript))
(defun ha-focus--command-callback (proc) (defun ha-focus--command-callback (proc)
"Asynchronously called when the `osascript' process finishes." "Asynchronously called when the `osascript' process finishes."
(message "Finished calling osascript.")) ;; ...
)
(global-set-key (kbd "<f7>") 'ha-focus-begin)
(global-set-key (kbd "S-<f7>") 'ha-focus-break)
(provide 'ha-focus) (provide 'ha-focus)
;;; ha-focus.el ends here ;;; ha-focus.el ends here

View file

@ -24,8 +24,7 @@ A literate programming file for configuring Emacs.
;; ;;
;;; Commentary: ;;; Commentary:
;; ;;
;; Basic configuration of Emacs. Should be executed early in the ;; Basic configuration of Emacs. Start early in the loading sequence.
;; loading sequence.
;; ;;
;;; Code: ;;; Code:
#+end_src #+end_src

View file

@ -41,7 +41,7 @@ I'm not trying an experiment where specially-placed function keys on my fancy er
:states '(normal visual motion) :states '(normal visual motion)
:keymaps 'override :keymaps 'override
:prefix "SPC" :prefix "SPC"
:non-normal-prefix "M-SPC" :non-normal-prefix "s-SPC"
:global-prefix "<f13>") :global-prefix "<f13>")
(general-create-definer ha-local-leader (general-create-definer ha-local-leader

View file

@ -3,7 +3,7 @@
#+date: 2020-09-18 #+date: 2020-09-18
#+tags: emacs org #+tags: emacs org
#+startup: inlineimages #+startup: inlineimages
#+lastmod: [2024-10-20 Sun] #+lastmod: [2024-10-25 Fri]
A literate programming file for configuring org-mode and those files. A literate programming file for configuring org-mode and those files.
@ -827,7 +827,11 @@ I've been working on my own [[http://www.howardism.org/Technical/Emacs/focused-w
:config :config
(ha-leader (ha-leader
"o f" '("begin focus" . ha-focus-begin) "o f" '("begin focus" . ha-focus-begin)
"o F" '("break focus" . ha-focus-break))) "o F" '("break focus" . ha-focus-break))
:bind
(("<f12>" . ha-focus-begin)
("S-<f12>" . ha-focus-interrupt)
("s-<f12>" . ha-focus-timer-left)))
#+end_src #+end_src
** Spell Checking ** Spell Checking
Let's hook some spell-checking into org files, and actually all text files. Im making this particularly delicious. Let's hook some spell-checking into org files, and actually all text files. Im making this particularly delicious.