Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jwiegley committed May 12, 2023
1 parent 105db42 commit ab27998
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 11 deletions.
101 changes: 90 additions & 11 deletions init.org
Expand Up @@ -1601,6 +1601,13 @@ non-empty directories is allowed."
(doc-view-resolution 300))
#+end_src

** easy-kill

#+begin_src emacs-lisp
(use-package easy-kill
:bind ([remap kill-ring-save] . easy-kill))
#+end_src

** edbi

#+begin_src emacs-lisp
Expand Down Expand Up @@ -2487,14 +2494,7 @@ up before you execute another command."
:commands git-undo)
#+end_src

** gitpatch

#+begin_src emacs-lisp
(use-package gitpatch
:commands gitpatch-mail)
#+end_src

** google-this
** COMMENT google-this

#+begin_src emacs-lisp
(use-package google-this
Expand Down Expand Up @@ -3432,6 +3432,13 @@ up before you execute another command."
(midnight-mode t))
#+end_src

** minesweeper

#+begin_src emacs-lisp
(use-package minesweeper
:commands minesweeper)
#+end_src

** moccur-edit

#+begin_src emacs-lisp
Expand Down Expand Up @@ -3858,7 +3865,36 @@ append it to ENTRY."

#+begin_src emacs-lisp
(use-package pcre2el
:commands (rxt-mode rxt-global-mode))
:bind
(:prefix-map
pcre2el-map
:prefix "C-c /"
;; a"Do-what-I-mean" commands:
("/" . rxt-explain)
("c" . rxt-convert-syntax)
("x" . rxt-convert-to-rx)
(")" . rxt-convert-to-strings)
("%" . pcre-query-replace-regexp)
("t" . rxt-toggle-elisp-rx)

;; Commands that work on a PCRE regexp:
:prefix-map
pcre2el-pcre-map
:prefix "C-c / p"
("e" . rxt-pcre-to-elisp)
("x" . rxt-pcre-to-rx)
(")" . rxt-pcre-to-strings)
("/" . rxt-explain-pcre)

;; Commands that work on an Emacs regexp:
:prefix-map
pcre2el-elisp-map
:prefix "C-c / e"
("/" . rxt-explain-elisp)
("p" . rxt-elisp-to-pcre)
("x" . rxt-elisp-to-rx)
(")" . rxt-elisp-to-strings)
("t" . rxt-toggle-elisp-rx)))
#+end_src

** pdf-tools
Expand Down Expand Up @@ -4558,6 +4594,7 @@ as both something that augments and replaces the standard auto-save-mode.

#+begin_src emacs-lisp
(use-package super-save
:unless alternate-emacs
:diminish
:custom
(super-save-auto-save-when-idle t)
Expand All @@ -4567,6 +4604,8 @@ as both something that augments and replaces the standard auto-save-mode.

** tagedit

A collection of paredit-like functions for editing in =html-mode=.

#+begin_src emacs-lisp
(use-package tagedit
:commands tagedit-mode)
Expand Down Expand Up @@ -4665,9 +4704,21 @@ as both something that augments and replaces the standard auto-save-mode.

** typo

[[https://github.com/jorgenschaefer/typoel][typo-mode]] is a buffer-specific minor mode that will change a number of normal
keys to make them insert typographically useful unicode characters. Some of
those keys can be used repeatedly to cycle through variations. This includes
in particular quotation marks and dashes.

=typo-global-mode= introduces a global minor mode which adds the =C-c 8= prefix to
complement Emacs’ default =C-x 8= prefix map.

#+begin_src emacs-lisp
(use-package typo
:commands typo-mode)
:diminish
:hook
(text-mode . typo-mode)
:config
(typo-global-mode 1))
#+end_src

** undo-propose
Expand Down Expand Up @@ -6030,7 +6081,6 @@ without white space and comments.
'(eglot (styles orderless basic))))
#+end_src


*** lisp-mode

#+begin_src emacs-lisp
Expand Down Expand Up @@ -6175,9 +6225,11 @@ without white space and comments.
("C-c ( J" . paredit-join-with-previous-list)
:map
lisp-mode-map
("M-r")
("<return>" . paredit-newline)
:map
emacs-lisp-mode-map
("M-r")
("<return>" . paredit-newline)))
#+end_src

Expand Down Expand Up @@ -9371,6 +9423,13 @@ To use this function, add it to `org-agenda-finalize-hook':
(org-crypt-use-before-save-magic))
#+end_src

*** org-drill

#+begin_src emacs-lisp
(use-package org-drill
:commands org-drill)
#+end_src

*** org-devonthink

#+begin_src emacs-lisp
Expand Down Expand Up @@ -9429,6 +9488,13 @@ To use this function, add it to `org-agenda-finalize-hook':
:after org)
#+end_src

*** org-pomodoro

#+begin_src emacs-lisp
(use-package org-pomodoro
:commands org-pomodoro)
#+end_src

*** org-ql

#+begin_src emacs-lisp
Expand Down Expand Up @@ -9830,6 +9896,19 @@ own lines, for instance.
:after org)
#+end_src

*** toc-org

#+begin_src emacs-lisp
(use-package toc-org
;; :bind
;; (:map markdown-mode-map
;; ("C-c C-o" . toc-org-markdown-follow-thing-at-point))
:hook
(org-mode . toc-org-mode)
;; (markdown-mode . toc-org-mode)
)
#+end_src

*** asana

#+begin_src emacs-lisp
Expand Down
69 changes: 69 additions & 0 deletions lisp/drafts.el
@@ -0,0 +1,69 @@
;;; drafts.el --- Write text first, act on it after

This comment has been minimized.

Copy link
@narendraj9

narendraj9 May 17, 2023

@jwiegley

I am sorry if this is too intrusive. I fed your really good description of what this package should do to chatgpt and was surprised by the output. It made a few really bad mistakes, e.g. putting the draft buffers in read-only mode, but in general seems to have given a great starting point.

I think the credit goes to your detailed writeup. :)

(require 'cl-lib)

(defgroup drafts nil
  "Write text first, act on it after"
  :group 'applications
  :prefix "drafts-")

(defcustom drafts-directory (expand-file-name "~/drafts")
  "Where drafts files are stored."
  :type 'string
  :group 'drafts)

(defcustom drafts-archive-directory
  (expand-file-name "~/drafts/Archive")
  "Where archives of drafts files are stored."
  :type 'string
  :group 'drafts)

(defcustom drafts-reset-delay-seconds 30
  "How long until a visited drafts buffer will be reset to empty."
  :type 'integer
  :group 'drafts)

(defcustom drafts-default-major-mode 'enriched-mode
  "Default major-mode for drafts buffer."
  :type 'symbol
  :group 'drafts)

(defcustom drafting-prompt-before-delete t
  "When non-nil, prompts before delete drafts file and buffer."
  :type 'boolean
  :group 'drafts)

(defcustom drafts-archive-when-killed t
  "When non-nil, archives killed drafts to drafts-archive-directory."
  :type 'boolean
  :group 'drafts)

(defvar drafts--time nil
  "Time when the current drafts buffer was created.")

(defvar drafts--buffer nil
  "The buffer associated with the current drafts.")

;;;###autoload
(defun drafts ()
  "Edit drafts in `drafts-directory'.
If it has been more than `drafts-reset-delay-seconds' since the last
time the latest drafts buffer was visited, a new, empty buffer is
created with `drafts-default-major-mode'.

Otherwise, revisit the latest drafts buffer."
  (interactive)
  (if (and drafts--time
	       (< (float-time (time-since drafts--time))
              drafts-reset-delay-seconds))
      (switch-to-buffer-other-window drafts--buffer)
    (setq drafts--time (current-time))
    (setq drafts--buffer (find-file (expand-file-name
                                     (format-time-string
                                      "%Y-%m-%d-%T.draft" drafts--time)
                                     drafts-directory)))
    (with-current-buffer drafts--buffer
      (rename-buffer (format "*Drafts: %s*"
                             (file-name-nondirectory
                              (buffer-file-name drafts--buffer))))
      (if (eq major-mode 'fundamental-mode)
          (funcall drafts-default-major-mode))
      (setq-local auto-save-default t)
      (setq-local backup-inhibited t)
      (add-hook 'focus-out-hook 'drafts--save nil t)
      (add-hook 'kill-buffer-hook 'drafts--remove nil t)
      (drafts-mode t))))

;;;###autoload
(defun drafts-browse ()
  "Browse drafts directory using dired."
  (interactive)
  (dired drafts-directory))

(defun drafts--save ()
  "Save the current drafts buffer and update timestamp."
  (when (derived-mode-p 'drafts-mode)
    (setq drafts--time (current-time))
    (save-buffer)))

(defun drafts--remove ()
  "Remove the current drafts buffer and file.

Prompt to confirm deletion if `drafting-prompt-before-delete' is
non-nil."
  (when (and (derived-mode-p 'drafts-mode)
	         (y-or-n-p
              (format "Remove drafts file `%s'?"
                      (buffer-name
                       (current-buffer)))))
    (when drafts-archive-when-killed
      (drafts--archive))
    (condition-case err
        (delete-file (buffer-file-name (current-buffer)))
      (file-missing nil))
    (kill-buffer (current-buffer))))

(defun drafts--archive ()
  "Archive file associated with the current drafts buffer."
  (let ((filename
	     (expand-file-name
	      (clone
	       (file-name-nondirectory (buffer-file-name (current-buffer)))
	       drafts-archive-directory))))
    (copy-file (buffer-file-name (current-buffer)) filename t t t t)))

(define-minor-mode drafts-mode
  "Minor mode for drafts buffers."
  :keymap (let ((map (make-sparse-keymap)))
            (unless window-system
              (define-key map (kbd "C-c C-k") 'drafts--remove)
              (define-key map (kbd "C-c C-c") 'drafts--act))
            map)
  (read-only-mode)
  (buffer-disable-undo))

(defun drafts--act ()
  "Act on content of current buffer."
  (interactive)
  (let ((content (buffer-string))
	    (filename (buffer-file-name (current-buffer))))
    (message "Acting on content of buffer `%s'..." (buffer-name))
    (drafts--archive)
    (kill-buffer (current-buffer))
    ;; Now `content' and `filename' should be acted on...
    ))

This comment has been minimized.

Copy link
@jwiegley

jwiegley May 23, 2023

Author Owner

That's pretty amazing @narendraj9! I'm traveling and on vacation until mid-June, but I definitely plan to take a deeper look then. Thank you so much for taking the initiative.


;; Copyright (C) 2023 John Wiegley <johnw@gnu.org>

;; Emacs Lisp Archive Entry
;; Filename: drafts.el
;; Version: 1.0
;; Keywords: text draft productivity
;; Author: John Wiegley <johnw@gnu.org>
;; Maintainer: John Wiegley <johnw@gnu.org>
;; Description: Write text first, act on it after
;; URL: https://github.com/jwiegley/drafts
;; Compatibility: Emacs28

;; This file is not part of GNU Emacs.

;; This is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 2, or (at your option) any later
;; version.
;;
;; This is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
;; for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.

;;; Commentary:

;; Use case:
;;
;; User types `M-x drafts', one of the two things happen:
;;
;; 1. If it has been more than `drafts-reset-delay-seconds' since the last
;; time the latest drafts buffer was visited, a new, empty buffer is
;; created with major-mode set to `drafts-default-major-mode'.
;;
;; 2. If it has been less than that amount of time, revisit the latest drafts
;; buffer.
;;
;; Old, empty drafts buffer are garbage collected.
;;
;; Each drafts buffer is associated with a file in the `drafts-directory',
;; whose name is formed from the timestamp when the draft was created.
;; Auto-saving is aggresively enabled in these buffers so that they are saved
;; very often, and also whenever focus moves away from the buffer.
;;
;; In the drafts buffer, the following key bindings are available through the
;; `drafts-mode-map':
;;
;; `C-c C-k' :: Kill the current drafts buffer and delete its associated file.
;; Prompts if `drafts-prompt-before-delete' is non-nil.
;;
;; `C-c C-c' :: "Act" on the content of the current drafts buffer. See below.
;;
;; When a draft is killed or acted on, the original file containing the draft
;; is archived to `drafts-archive-directory'. To avoid archiving killed
;; drafts, set `drafts-archive-when-killed' to `nil'.
;;
;; The command `M-x drafts-browse' will open the `drafts-directory' in dired,
;; so that you can manage or revisit those files directly. Each file bears the
;; extension ".draft" in order to know that the default major-mode and drafts
;; minor-mode should be active.

(provide 'drafts)
12 changes: 12 additions & 0 deletions lisp/org-balance.el
@@ -1,3 +1,15 @@
;; `org-todo-score' algorithm:
;;
;; todo metadata:
;;
;; - Number of days since creation
;; - Number of other tasks in the same project/category
;; - Number of tasks in that project/category closed since creation date
;; - Date when last task in that project/category was closed
;; - Priority of the task
;; - Number of tasks with same priority or higher in the project/category
;; - Number of tasks closed in that project/category in the last quarter

(defun org-todo-score (&optional ignore)
"Compute the score of an Org-mode task.
Age gradually decreases the value given to a task. After 28
Expand Down

0 comments on commit ab27998

Please sign in to comment.