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; -*-
;;
;; Copyright (C) 2021 Howard X. Abrams
;; Copyright © 2021,2024 Howard X. Abrams
;;
;; 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
;;
;; 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:
;; ~/website/Technical/Emacs/focused-work.org
;; And tangle the file to recreate this one.
@ -18,7 +23,7 @@
(defun ha-focus-countdown-timer (minutes fun)
(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 ()
"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")
(if (eq major-mode 'org-mode)
(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 ()
"Stop the focused time by stopping the music.
This also starts another break timer, that calls
`ha-focus-break-over' when finished."
(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")
(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 ()
"Spin up a capture window."
(ignore-errors
(org-capture nil "cc")
(sit-for 1)
(org-clock-out))
(ha-focus-countdown-timer 5 'ha-focus-break-over)
(message "Taking a much needed break..."))
(org-clock-out)))
(defun ha-focus-break-over ()
"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."
(ha-focus--command "set v to output volume of (get volume settings)
set volume output volume 1
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)
"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)
"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)
;;; ha-focus.el ends here

View file

@ -24,8 +24,7 @@ A literate programming file for configuring Emacs.
;;
;;; Commentary:
;;
;; Basic configuration of Emacs. Should be executed early in the
;; loading sequence.
;; Basic configuration of Emacs. Start early in the loading sequence.
;;
;;; Code:
#+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)
:keymaps 'override
:prefix "SPC"
:non-normal-prefix "M-SPC"
:non-normal-prefix "s-SPC"
:global-prefix "<f13>")
(general-create-definer ha-local-leader

View file

@ -3,7 +3,7 @@
#+date: 2020-09-18
#+tags: emacs org
#+startup: inlineimages
#+lastmod: [2024-10-20 Sun]
#+lastmod: [2024-10-25 Fri]
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
(ha-leader
"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
** Spell Checking
Let's hook some spell-checking into org files, and actually all text files. Im making this particularly delicious.