ido-completing-read+ added

This commit is contained in:
KemoNine 2022-04-21 23:09:27 -04:00
parent 7dab9f42d9
commit 3a314a9d2b
26 changed files with 3322 additions and 106 deletions

View File

@ -0,0 +1,104 @@
;;; ido-completing-read+-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (directory-file-name
(or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "ido-completing-read+" "ido-completing-read+.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from ido-completing-read+.el
(defvar ido-cr+-minibuffer-depth -1 "\
Minibuffer depth of the most recent ido-cr+ activation.
If this equals the current minibuffer depth, then the minibuffer
is currently being used by ido-cr+, and ido-cr+ features will be
active. Otherwise, something else is using the minibuffer and
ido-cr+ features will be deactivated to avoid interfering with
the other command.
This is set to -1 by default, since `(minibuffer-depth)' should
never return this value.")
(defvar ido-cr+-replace-completely nil "\
If non-nil, replace `ido-completeing-read' completely with ido-cr+.
Enabling this may interfere with or cause errors in other
packages that use `ido-completing-read'. If you discover any such
incompatibilities, please file a bug report at
https://github.com/DarwinAwardWinner/ido-completing-read-plus/issues")
(custom-autoload 'ido-cr+-replace-completely "ido-completing-read+" t)
(defsubst ido-cr+-active nil "\
Return non-nil if ido-cr+ is currently using the minibuffer." (>= ido-cr+-minibuffer-depth (minibuffer-depth)))
(autoload 'ido-completing-read+ "ido-completing-read+" "\
Ido-based method for reading from the minibuffer with completion.
See `completing-read' for the meaning of the arguments.
This function is a wrapper for `ido-completing-read' designed to
be used as the value of `completing-read-function'. Importantly,
it detects edge cases that ido cannot handle and uses normal
completion for them.
See `completing-read' for the meaning of the arguments.
\(fn PROMPT COLLECTION &optional PREDICATE REQUIRE-MATCH INITIAL-INPUT HIST DEF INHERIT-INPUT-METHOD)" nil nil)
(autoload 'ido-completing-read@ido-cr+-replace "ido-completing-read+" "\
This advice allows ido-cr+ to completely replace `ido-completing-read'.
See the varaible `ido-cr+-replace-completely' for more information.
\(fn ORIG-FUN &rest ARGS)" nil nil)
(advice-add 'ido-completing-read :around #'ido-completing-read@ido-cr+-replace)
(autoload 'call-interactively@ido-cr+-record-current-command "ido-completing-read+" "\
Let-bind the command being interactively called.
See `ido-cr+-current-command' for more information.
\(fn ORIG-FUN COMMAND &rest ARGS)" nil nil)
(advice-add 'call-interactively :around #'call-interactively@ido-cr+-record-current-command)
(defvar ido-ubiquitous-mode nil "\
Non-nil if Ido-Ubiquitous mode is enabled.
See the `ido-ubiquitous-mode' command
for a description of this minor mode.
Setting this variable directly does not take effect;
either customize it (see the info node `Easy Customization')
or call the function `ido-ubiquitous-mode'.")
(custom-autoload 'ido-ubiquitous-mode "ido-completing-read+" nil)
(autoload 'ido-ubiquitous-mode "ido-completing-read+" "\
Use ido completion instead of standard completion almost everywhere.
If called interactively, enable Ido-Ubiquitous mode if ARG is
positive, and disable it if ARG is zero or negative. If called
from Lisp, also enable the mode if ARG is omitted or nil, and
toggle it if ARG is `toggle'; disable the mode otherwise.
If this mode causes problems for a function, you can customize
when ido completion is or is not used by customizing
`ido-cr+-disable-list'.
\(fn &optional ARG)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "ido-completing-read+" '("ido-" "minibuf-eldef-update-minibuffer@ido-cr+-compat")))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; ido-completing-read+-autoloads.el ends here

View File

@ -0,0 +1,2 @@
;;; Generated package description from ido-completing-read+.el -*- no-byte-compile: t -*-
(define-package "ido-completing-read+" "20210529.1318" "A completing-read-function using ido" '((emacs "24.4") (seq "0.5") (memoize "1.1")) :commit "49e7967ea8c0ab0a206b40d70fc19be115083fa1" :authors '(("Ryan C. Thompson" . "rct@thompsonclan.org")) :maintainer '("Ryan C. Thompson" . "rct@thompsonclan.org") :keywords '("ido" "completion" "convenience") :url "https://github.com/DarwinAwardWinner/ido-completing-read-plus")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
;;; memoize-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (directory-file-name
(or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "memoize" "memoize.el" (0 0 0 0))
;;; Generated autoloads from memoize.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "memoize" '("defmemoize" "memoize")))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; memoize-autoloads.el ends here

View File

@ -0,0 +1,2 @@
;;; Generated package description from memoize.el -*- no-byte-compile: t -*-
(define-package "memoize" "20200103.2036" "Memoization functions" 'nil :commit "51b075935ca7070f62fae1d69fe0ff7d8fa56fdd" :authors '(("Christopher Wellons" . "mosquitopsu@gmail.com")) :maintainer '("Christopher Wellons" . "mosquitopsu@gmail.com") :url "https://github.com/skeeto/emacs-memoize")

View File

@ -0,0 +1,190 @@
;;; memoize.el --- Memoization functions -*- lexical-binding: t; -*-
;; This is free and unencumbered software released into the public domain.
;; Author: Christopher Wellons <mosquitopsu@gmail.com>
;; URL: https://github.com/skeeto/emacs-memoize
;; Package-Version: 20200103.2036
;; Package-Commit: 51b075935ca7070f62fae1d69fe0ff7d8fa56fdd
;; Version: 1.1
;;; Commentary:
;; `memoize' accepts a symbol or a function. When given a symbol, the
;; symbol's function definition is memoized and installed overtop of
;; the original function definition. When given a function, it returns
;; a memoized version of that function.
;; (memoize 'my-expensive-function)
;; `defmemoize' defines a memoized function directly, behaving just
;; like `defun'.
;; (defmemoize my-expensive-function (n)
;; (if (zerop n)
;; 1
;; (* n (my-expensive-function (1- n)))))
;; Memoizing an interactive function will render that function
;; non-interactive. It would be easy to fix this problem when it comes
;; to non-byte-compiled functions, but recovering the interactive
;; definition from a byte-compiled function is more complex than I
;; care to deal with. Besides, interactive functions are always used
;; for their side effects anyway.
;; There's no way to memoize nil returns, but why would your expensive
;; functions do all that work just to return nil? :-)
;; Memoization takes up memory, which should be freed at some point.
;; Because of this, all memoization has a timeout from when the last
;; access was. The default timeout is set by
;; `memoize-default-timeout'. It can be overridden by using the
;; `memoize' function, but the `defmemoize' macro will always just use
;; the default timeout.
;; If you wait to byte-compile the function until *after* it is
;; memoized then the function and memoization wrapper both get
;; compiled at once, so there's no special reason to do them
;; separately. But there really isn't much advantage to compiling the
;; memoization wrapper anyway.
;;; Code:
(require 'cl-lib)
(defvar memoize-default-timeout "2 hours"
"The amount of time after which to remove a memoization.
This represents the time after last use of the memoization after
which the value is expired. Setting this to nil means to never
expire, which will cause a memory leak, but may be acceptable for
very careful uses.")
(defun memoize (func &optional timeout)
"Memoize FUNC: a closure, lambda, or symbol.
If argument is a symbol then install the memoized function over
the original function. The TIMEOUT value, a timeout string as
used by `run-at-time' will determine when the value expires, and
will apply after the last access (unless another access
happens)."
(cl-typecase func
(symbol
(when (get func :memoize-original-function)
(user-error "%s is already memoized" func))
(put func :memoize-original-documentation (documentation func))
(put func 'function-documentation
(concat (documentation func) " (memoized)"))
(put func :memoize-original-function (symbol-function func))
(fset func (memoize--wrap (symbol-function func) timeout))
func)
(function (memoize--wrap func timeout))))
(defun memoize-restore (func)
"Restore the original, non-memoized definition of FUNC.
FUNC should be a symbol which has been memoized with `memoize'."
(unless (get func :memoize-original-function)
(user-error "%s is not memoized" func))
(fset func (get func :memoize-original-function))
(put func :memoize-original-function nil)
(put func 'function-documentation
(get func :memoize-original-documentation))
(put func :memoize-original-documentation nil))
(defun memoize--wrap (func timeout)
"Return the memoized version of FUNC.
TIMEOUT specifies how long the values last from last access. A
nil timeout will cause the values to never expire, which will
cause a memory leak as memoize is use, so use the nil value with
care."
(let ((table (make-hash-table :test 'equal))
(timeouts (make-hash-table :test 'equal)))
(lambda (&rest args)
(let ((value (gethash args table)))
(unwind-protect
(or value (puthash args (apply func args) table))
(let ((existing-timer (gethash args timeouts))
(timeout-to-use (or timeout memoize-default-timeout)))
(when existing-timer
(cancel-timer existing-timer))
(when timeout-to-use
(puthash args
(run-at-time timeout-to-use nil
(lambda ()
(remhash args table))) timeouts))))))))
(defmacro defmemoize (name arglist &rest body)
"Create a memoize'd function. NAME, ARGLIST, DOCSTRING and BODY
have the same meaning as in `defun'."
(declare (indent 2) (doc-string 3) (debug defun))
`(progn
(defun ,name ,arglist
,@body)
(memoize (quote ,name))))
(defun memoize-by-buffer-contents (func)
"Memoize the given function by buffer contents.
If argument is a symbol then install the memoized function over
the original function."
(cl-typecase func
(symbol
(put func 'function-documentation
(concat (documentation func) " (memoized by buffer contents)"))
(fset func (memoize-by-buffer-contents--wrap (symbol-function func)))
func)
(function (memoize-by-buffer-contents--wrap func))))
(defun memoize-by-buffer-contents--wrap (func)
"Return the memoization based on the buffer contents of FUNC.
This form of memoization will be based off the current buffer
contents. A different memoization is stored for all buffer
contents, although old contents and no-longer-existant buffers
will get garbage collected."
;; We need 3 tables here to properly garbage collect. First is the
;; table for the memoization itself, `memoization-table'. It holds a
;; cons of the content hash and the function arguments.
;;
;; Buffer contents change often, though, so we want these entries to
;; be automatically garbage collected when the buffer changes or the
;; buffer goes away. To keep the entries around, we need to tie the
;; content hash to the buffer, so that the content hash string
;; doesn't go away until the buffer does. We do that with the
;; `buffer-to-contents-table'.
;;
;; But even if the buffer content does change, we need to expire the
;; memoization entries for that particular buffer content. So we
;; have a `contents-to-memoization-table' that we use to tie the
;; content hash to the memoization conses used as keys in the
;; `memoization-table'.
;;
;; If a buffer's value changes, we make sure the next time we put a
;; new value at the `buffer-to-contents-table', which causes the
;; hash string to disappear. This causes the hash-string to
;; disappear from the `contents-to-memoization-table', which causes
;; the memoizations based on that content string to disappear from
;; the `memoization-table'.
(let ((memoization-table (make-hash-table :test 'equal :weakness 'key))
(buffer-to-contents-table (make-hash-table :weakness 'key))
(contents-to-memoization-table (make-hash-table :weakness 'key)))
(lambda (&rest args)
(let* ((bufhash (secure-hash 'md5 (buffer-string)))
(memokey (cons bufhash args))
(value (gethash memokey memoization-table)))
(or value
(progn
(puthash (current-buffer) bufhash buffer-to-contents-table)
(puthash bufhash memokey contents-to-memoization-table)
(puthash memokey (apply func args) memoization-table)))))))
(defmacro defmemoize-by-buffer-contents (name arglist &rest body)
"Create a memoize'd-by-buffer-contents function. NAME, ARGLIST,
DOCSTRING and BODY have the same meaning as in `defun'."
(declare (indent defun))
`(progn
(defun ,name ,arglist
,@body)
(memoize-by-buffer-contents (quote ,name))))
(provide 'memoize)
;;; memoize.el ends here

Binary file not shown.

View File

@ -21,10 +21,10 @@
(min-pixel-height-safe . 20)
(min-pixel-width-safe . 20))
leaf
(pixel-width . 1262)
(pixel-height . 1262)
(total-width . 126)
(total-height . 63)
(pixel-width . 837)
(pixel-height . 700)
(total-width . 83)
(total-height . 35)
(normal-height . 1.0)
(normal-width . 1.0)
(buffer "config.go"

View File

@ -1,6 +1,8 @@
;; -*- mode: emacs-lisp; eval: (progn (pp-buffer) (indent-buffer)) -*-
((def-persp nil
((def-buffer "layer-3---other.json" "c:/Users/mcros/Nextcloud/org/keyboards/pockettype/layer-3---other.json" json-mode)
((def-buffer "config.go" "c:/Users/mcros/src/piframe-go/ui/config.go" go-mode)
(def-buffer "watchdog.go" "c:/Users/mcros/src/piframe-go/watchdog/watchdog.go" go-mode)
(def-buffer "layer-3---other.json" "c:/Users/mcros/Nextcloud/org/keyboards/pockettype/layer-3---other.json" json-mode)
(def-buffer "Readme.md" "c:/Users/mcros/Nextcloud/org/Readme.md" markdown-mode)
(def-buffer "blog_posts.org" "c:/Users/mcros/Nextcloud/org/blog_posts.org" org-mode)
(def-buffer ".owncloudsync.log" "c:/Users/mcros/Nextcloud/.owncloudsync.log" fundamental-mode)
@ -25,7 +27,7 @@
(total-height . 63)
(normal-height . 1.0)
(normal-width . 1.0)
(buffer "layer-3---other.json"
(buffer "config.go"
(selected . t)
(hscroll . 0)
(fringes 8 8 nil nil)
@ -33,9 +35,11 @@
(scroll-bars nil 3 t nil 0 t nil)
(vscroll . 0)
(dedicated)
(point . 528)
(start . 1))
(point . 568)
(start . 432))
(prev-buffers
("watchdog.go" 1 587)
("layer-3---other.json" 1 528)
("Readme.md" 1 1)
("blog_posts.org" 8764 8764)
(".owncloudsync.log" 1 1)

View File

@ -1,5 +1,10 @@
;; -*- mode: emacs-lisp; eval: (progn (pp-buffer) (indent-buffer)) -*-
((def-persp nil nil
((def-persp nil
((def-buffer "layer-3---other.json" "c:/Users/mcros/Nextcloud/org/keyboards/pockettype/layer-3---other.json" json-mode)
(def-buffer "Readme.md" "c:/Users/mcros/Nextcloud/org/Readme.md" markdown-mode)
(def-buffer "blog_posts.org" "c:/Users/mcros/Nextcloud/org/blog_posts.org" org-mode)
(def-buffer ".owncloudsync.log" "c:/Users/mcros/Nextcloud/.owncloudsync.log" fundamental-mode)
(def-buffer "links.md" "c:/Users/mcros/Nextcloud/links.md" markdown-mode))
(def-wconf
(((min-height . 4)
(min-width . 10)
@ -14,13 +19,13 @@
(min-pixel-height-safe . 20)
(min-pixel-width-safe . 20))
leaf
(pixel-width . 837)
(pixel-height . 700)
(total-width . 83)
(total-height . 35)
(pixel-width . 1262)
(pixel-height . 1262)
(total-width . 126)
(total-height . 63)
(normal-height . 1.0)
(normal-width . 1.0)
(buffer "*scratch*"
(buffer "layer-3---other.json"
(selected . t)
(hscroll . 0)
(fringes 8 8 nil nil)
@ -28,7 +33,13 @@
(scroll-bars nil 3 t nil 0 t nil)
(vscroll . 0)
(dedicated)
(point . 146)
(start . 1))))
(point . 528)
(start . 1))
(prev-buffers
("Readme.md" 1 1)
("blog_posts.org" 8764 8764)
(".owncloudsync.log" 1 1)
("links.md" 1 3418)
("*scratch*" 1 1))))
(def-params nil)
t nil nil))

View File

@ -29,8 +29,6 @@
(vscroll . 0)
(dedicated)
(point . 146)
(start . 1))
(prev-buffers
("*scratch*" 1 146))))
(start . 1))))
(def-params nil)
t nil nil))

View File

@ -4,7 +4,7 @@
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;(package-initialize) ; this goes in chemacs2 init -- DO NOT UNCOMMENT
(add-to-list 'package-selected-packages
'(helpful dired-rainbow dired-collapse dired-ranger dired-single all-the-icons-dired diminish persp-mode modus-themes transpose-frame use-package)
'(helpful dired-rainbow dired-collapse dired-ranger dired-single all-the-icons-dired ido-completing-read+ diminish persp-mode modus-themes transpose-frame use-package)
)
(require 'use-package)
@ -31,6 +31,8 @@
; Set some global config
(setq inhibit-splash-screen t) ; why do you need to tell me things i know by default
; Turn on ido mode (useful for buffer swaps and find file completion)
(require 'ido-completing-read+)
(ido-ubiquitous-mode 1)
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode 1)

View File

@ -2,9 +2,14 @@ https://github.com/Bad-ptr/persp-mode.el
https://github.com/minad/vertico
capture template for week in review?
ido-ubiquitous
ido-vertical-mode
verify rainbow delimineters
verify rainbow mode
add keyboard shortcuts for origami code folding (on/off/fold/unfold)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -81,6 +86,7 @@ open scratch buffer. paste below into it as the contents then do `M-x ev-b RET`
modus-themes
persp-mode
diminish
ido-completing-read+
all-the-icons-dired
dired-single
dired-ranger

View File

@ -0,0 +1,104 @@
;;; ido-completing-read+-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (directory-file-name
(or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "ido-completing-read+" "ido-completing-read+.el"
;;;;;; (0 0 0 0))
;;; Generated autoloads from ido-completing-read+.el
(defvar ido-cr+-minibuffer-depth -1 "\
Minibuffer depth of the most recent ido-cr+ activation.
If this equals the current minibuffer depth, then the minibuffer
is currently being used by ido-cr+, and ido-cr+ features will be
active. Otherwise, something else is using the minibuffer and
ido-cr+ features will be deactivated to avoid interfering with
the other command.
This is set to -1 by default, since `(minibuffer-depth)' should
never return this value.")
(defvar ido-cr+-replace-completely nil "\
If non-nil, replace `ido-completeing-read' completely with ido-cr+.
Enabling this may interfere with or cause errors in other
packages that use `ido-completing-read'. If you discover any such
incompatibilities, please file a bug report at
https://github.com/DarwinAwardWinner/ido-completing-read-plus/issues")
(custom-autoload 'ido-cr+-replace-completely "ido-completing-read+" t)
(defsubst ido-cr+-active nil "\
Return non-nil if ido-cr+ is currently using the minibuffer." (>= ido-cr+-minibuffer-depth (minibuffer-depth)))
(autoload 'ido-completing-read+ "ido-completing-read+" "\
Ido-based method for reading from the minibuffer with completion.
See `completing-read' for the meaning of the arguments.
This function is a wrapper for `ido-completing-read' designed to
be used as the value of `completing-read-function'. Importantly,
it detects edge cases that ido cannot handle and uses normal
completion for them.
See `completing-read' for the meaning of the arguments.
\(fn PROMPT COLLECTION &optional PREDICATE REQUIRE-MATCH INITIAL-INPUT HIST DEF INHERIT-INPUT-METHOD)" nil nil)
(autoload 'ido-completing-read@ido-cr+-replace "ido-completing-read+" "\
This advice allows ido-cr+ to completely replace `ido-completing-read'.
See the varaible `ido-cr+-replace-completely' for more information.
\(fn ORIG-FUN &rest ARGS)" nil nil)
(advice-add 'ido-completing-read :around #'ido-completing-read@ido-cr+-replace)
(autoload 'call-interactively@ido-cr+-record-current-command "ido-completing-read+" "\
Let-bind the command being interactively called.
See `ido-cr+-current-command' for more information.
\(fn ORIG-FUN COMMAND &rest ARGS)" nil nil)
(advice-add 'call-interactively :around #'call-interactively@ido-cr+-record-current-command)
(defvar ido-ubiquitous-mode nil "\
Non-nil if Ido-Ubiquitous mode is enabled.
See the `ido-ubiquitous-mode' command
for a description of this minor mode.
Setting this variable directly does not take effect;
either customize it (see the info node `Easy Customization')
or call the function `ido-ubiquitous-mode'.")
(custom-autoload 'ido-ubiquitous-mode "ido-completing-read+" nil)
(autoload 'ido-ubiquitous-mode "ido-completing-read+" "\
Use ido completion instead of standard completion almost everywhere.
If called interactively, enable Ido-Ubiquitous mode if ARG is
positive, and disable it if ARG is zero or negative. If called
from Lisp, also enable the mode if ARG is omitted or nil, and
toggle it if ARG is `toggle'; disable the mode otherwise.
If this mode causes problems for a function, you can customize
when ido completion is or is not used by customizing
`ido-cr+-disable-list'.
\(fn &optional ARG)" t nil)
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "ido-completing-read+" '("ido-" "minibuf-eldef-update-minibuffer@ido-cr+-compat")))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; ido-completing-read+-autoloads.el ends here

View File

@ -0,0 +1,2 @@
;;; Generated package description from ido-completing-read+.el -*- no-byte-compile: t -*-
(define-package "ido-completing-read+" "20210529.1318" "A completing-read-function using ido" '((emacs "24.4") (seq "0.5") (memoize "1.1")) :commit "49e7967ea8c0ab0a206b40d70fc19be115083fa1" :authors '(("Ryan C. Thompson" . "rct@thompsonclan.org")) :maintainer '("Ryan C. Thompson" . "rct@thompsonclan.org") :keywords '("ido" "completion" "convenience") :url "https://github.com/DarwinAwardWinner/ido-completing-read-plus")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
;;; memoize-autoloads.el --- automatically extracted autoloads
;;
;;; Code:
(add-to-list 'load-path (directory-file-name
(or (file-name-directory #$) (car load-path))))
;;;### (autoloads nil "memoize" "memoize.el" (0 0 0 0))
;;; Generated autoloads from memoize.el
(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "memoize" '("defmemoize" "memoize")))
;;;***
;; Local Variables:
;; version-control: never
;; no-byte-compile: t
;; no-update-autoloads: t
;; coding: utf-8
;; End:
;;; memoize-autoloads.el ends here

View File

@ -0,0 +1,2 @@
;;; Generated package description from memoize.el -*- no-byte-compile: t -*-
(define-package "memoize" "20200103.2036" "Memoization functions" 'nil :commit "51b075935ca7070f62fae1d69fe0ff7d8fa56fdd" :authors '(("Christopher Wellons" . "mosquitopsu@gmail.com")) :maintainer '("Christopher Wellons" . "mosquitopsu@gmail.com") :url "https://github.com/skeeto/emacs-memoize")

View File

@ -0,0 +1,190 @@
;;; memoize.el --- Memoization functions -*- lexical-binding: t; -*-
;; This is free and unencumbered software released into the public domain.
;; Author: Christopher Wellons <mosquitopsu@gmail.com>
;; URL: https://github.com/skeeto/emacs-memoize
;; Package-Version: 20200103.2036
;; Package-Commit: 51b075935ca7070f62fae1d69fe0ff7d8fa56fdd
;; Version: 1.1
;;; Commentary:
;; `memoize' accepts a symbol or a function. When given a symbol, the
;; symbol's function definition is memoized and installed overtop of
;; the original function definition. When given a function, it returns
;; a memoized version of that function.
;; (memoize 'my-expensive-function)
;; `defmemoize' defines a memoized function directly, behaving just
;; like `defun'.
;; (defmemoize my-expensive-function (n)
;; (if (zerop n)
;; 1
;; (* n (my-expensive-function (1- n)))))
;; Memoizing an interactive function will render that function
;; non-interactive. It would be easy to fix this problem when it comes
;; to non-byte-compiled functions, but recovering the interactive
;; definition from a byte-compiled function is more complex than I
;; care to deal with. Besides, interactive functions are always used
;; for their side effects anyway.
;; There's no way to memoize nil returns, but why would your expensive
;; functions do all that work just to return nil? :-)
;; Memoization takes up memory, which should be freed at some point.
;; Because of this, all memoization has a timeout from when the last
;; access was. The default timeout is set by
;; `memoize-default-timeout'. It can be overridden by using the
;; `memoize' function, but the `defmemoize' macro will always just use
;; the default timeout.
;; If you wait to byte-compile the function until *after* it is
;; memoized then the function and memoization wrapper both get
;; compiled at once, so there's no special reason to do them
;; separately. But there really isn't much advantage to compiling the
;; memoization wrapper anyway.
;;; Code:
(require 'cl-lib)
(defvar memoize-default-timeout "2 hours"
"The amount of time after which to remove a memoization.
This represents the time after last use of the memoization after
which the value is expired. Setting this to nil means to never
expire, which will cause a memory leak, but may be acceptable for
very careful uses.")
(defun memoize (func &optional timeout)
"Memoize FUNC: a closure, lambda, or symbol.
If argument is a symbol then install the memoized function over
the original function. The TIMEOUT value, a timeout string as
used by `run-at-time' will determine when the value expires, and
will apply after the last access (unless another access
happens)."
(cl-typecase func
(symbol
(when (get func :memoize-original-function)
(user-error "%s is already memoized" func))
(put func :memoize-original-documentation (documentation func))
(put func 'function-documentation
(concat (documentation func) " (memoized)"))
(put func :memoize-original-function (symbol-function func))
(fset func (memoize--wrap (symbol-function func) timeout))
func)
(function (memoize--wrap func timeout))))
(defun memoize-restore (func)
"Restore the original, non-memoized definition of FUNC.
FUNC should be a symbol which has been memoized with `memoize'."
(unless (get func :memoize-original-function)
(user-error "%s is not memoized" func))
(fset func (get func :memoize-original-function))
(put func :memoize-original-function nil)
(put func 'function-documentation
(get func :memoize-original-documentation))
(put func :memoize-original-documentation nil))
(defun memoize--wrap (func timeout)
"Return the memoized version of FUNC.
TIMEOUT specifies how long the values last from last access. A
nil timeout will cause the values to never expire, which will
cause a memory leak as memoize is use, so use the nil value with
care."
(let ((table (make-hash-table :test 'equal))
(timeouts (make-hash-table :test 'equal)))
(lambda (&rest args)
(let ((value (gethash args table)))
(unwind-protect
(or value (puthash args (apply func args) table))
(let ((existing-timer (gethash args timeouts))
(timeout-to-use (or timeout memoize-default-timeout)))
(when existing-timer
(cancel-timer existing-timer))
(when timeout-to-use
(puthash args
(run-at-time timeout-to-use nil
(lambda ()
(remhash args table))) timeouts))))))))
(defmacro defmemoize (name arglist &rest body)
"Create a memoize'd function. NAME, ARGLIST, DOCSTRING and BODY
have the same meaning as in `defun'."
(declare (indent 2) (doc-string 3) (debug defun))
`(progn
(defun ,name ,arglist
,@body)
(memoize (quote ,name))))
(defun memoize-by-buffer-contents (func)
"Memoize the given function by buffer contents.
If argument is a symbol then install the memoized function over
the original function."
(cl-typecase func
(symbol
(put func 'function-documentation
(concat (documentation func) " (memoized by buffer contents)"))
(fset func (memoize-by-buffer-contents--wrap (symbol-function func)))
func)
(function (memoize-by-buffer-contents--wrap func))))
(defun memoize-by-buffer-contents--wrap (func)
"Return the memoization based on the buffer contents of FUNC.
This form of memoization will be based off the current buffer
contents. A different memoization is stored for all buffer
contents, although old contents and no-longer-existant buffers
will get garbage collected."
;; We need 3 tables here to properly garbage collect. First is the
;; table for the memoization itself, `memoization-table'. It holds a
;; cons of the content hash and the function arguments.
;;
;; Buffer contents change often, though, so we want these entries to
;; be automatically garbage collected when the buffer changes or the
;; buffer goes away. To keep the entries around, we need to tie the
;; content hash to the buffer, so that the content hash string
;; doesn't go away until the buffer does. We do that with the
;; `buffer-to-contents-table'.
;;
;; But even if the buffer content does change, we need to expire the
;; memoization entries for that particular buffer content. So we
;; have a `contents-to-memoization-table' that we use to tie the
;; content hash to the memoization conses used as keys in the
;; `memoization-table'.
;;
;; If a buffer's value changes, we make sure the next time we put a
;; new value at the `buffer-to-contents-table', which causes the
;; hash string to disappear. This causes the hash-string to
;; disappear from the `contents-to-memoization-table', which causes
;; the memoizations based on that content string to disappear from
;; the `memoization-table'.
(let ((memoization-table (make-hash-table :test 'equal :weakness 'key))
(buffer-to-contents-table (make-hash-table :weakness 'key))
(contents-to-memoization-table (make-hash-table :weakness 'key)))
(lambda (&rest args)
(let* ((bufhash (secure-hash 'md5 (buffer-string)))
(memokey (cons bufhash args))
(value (gethash memokey memoization-table)))
(or value
(progn
(puthash (current-buffer) bufhash buffer-to-contents-table)
(puthash bufhash memokey contents-to-memoization-table)
(puthash memokey (apply func args) memoization-table)))))))
(defmacro defmemoize-by-buffer-contents (name arglist &rest body)
"Create a memoize'd-by-buffer-contents function. NAME, ARGLIST,
DOCSTRING and BODY have the same meaning as in `defun'."
(declare (indent defun))
`(progn
(defun ,name ,arglist
,@body)
(memoize-by-buffer-contents (quote ,name))))
(provide 'memoize)
;;; memoize.el ends here

Binary file not shown.

View File

@ -1,43 +1,72 @@
;; -*- mode: emacs-lisp; eval: (progn (pp-buffer) (indent-buffer)) -*-
((def-persp nil
((def-buffer "_todo.org" "c:/Users/mcros/Nextcloud/org/_todo.org" org-mode)
(def-buffer "_index.org" "c:/Users/mcros/Nextcloud/org/_index.org" org-mode)
((def-buffer "_index.org" "c:/Users/mcros/Nextcloud/org/_index.org" org-mode)
(def-buffer "_todo.org" "c:/Users/mcros/Nextcloud/org/_todo.org" org-mode)
(def-buffer "_index_phone.org" "c:/Users/mcros/Nextcloud/org/_index_phone.org" org-mode)
(def-buffer "_health.org" "c:/Users/mcros/Nextcloud/org/health/_health.org" org-mode)
(def-buffer "health_houdini.org" "c:/Users/mcros/Nextcloud/org/health/health_houdini.org" org-mode)
(def-buffer "health_mike.org" "c:/Users/mcros/Nextcloud/org/health/health_mike.org" org-mode))
(def-wconf
(((min-height . 4)
(((min-height . 8)
(min-width . 10)
(min-height-ignore . 3)
(min-height-ignore . 6)
(min-width-ignore . 6)
(min-height-safe . 1)
(min-height-safe . 2)
(min-width-safe . 2)
(min-pixel-height . 80)
(min-pixel-height . 160)
(min-pixel-width . 100)
(min-pixel-height-ignore . 60)
(min-pixel-height-ignore . 120)
(min-pixel-width-ignore . 60)
(min-pixel-height-safe . 20)
(min-pixel-height-safe . 40)
(min-pixel-width-safe . 20))
leaf
vc
(pixel-width . 837)
(pixel-height . 700)
(total-width . 83)
(total-height . 35)
(normal-height . 1.0)
(normal-width . 1.0)
(buffer "_todo.org"
(selected . t)
(hscroll . 0)
(fringes 8 8 nil nil)
(margins nil)
(scroll-bars nil 3 t nil 0 t nil)
(vscroll . 0)
(dedicated)
(point . 1)
(start . 1))
(prev-buffers
("*Org Agenda*" 1 1142)
("*scratch*" 1 1))))
(combination-limit)
(leaf
(pixel-width . 837)
(pixel-height . 300)
(total-width . 83)
(total-height . 15)
(normal-height . 0.4411764705882353)
(normal-width . 1.0)
(buffer "*Org Agenda*"
(selected)
(hscroll . 0)
(fringes 8 8 nil nil)
(margins nil)
(scroll-bars nil 3 t nil 0 t nil)
(vscroll . 0)
(dedicated . "t")
(point . 1)
(start . 1))
(prev-buffers
("*scratch*" 1 1)))
(leaf
(last . t)
(pixel-width . 837)
(pixel-height . 400)
(total-width . 83)
(total-height . 20)
(normal-height . 0.5588235294117647)
(normal-width . 1.0)
(buffer "_index.org"
(selected . t)
(hscroll . 0)
(fringes 8 8 nil nil)
(margins nil)
(scroll-bars nil 3 t nil 0 t nil)
(vscroll . 0)
(dedicated)
(point . 1)
(start . 1))
(prev-buffers
("_todo.org" 1 1)
("_index_phone.org" 1 1)
("*Org Agenda*" 1 1)))))
(def-params nil)
t nil nil))

View File

@ -1,7 +1,7 @@
;; -*- mode: emacs-lisp; eval: (progn (pp-buffer) (indent-buffer)) -*-
((def-persp nil
((def-buffer "_index.org" "c:/Users/mcros/Nextcloud/org/_index.org" org-mode)
(def-buffer "_todo.org" "c:/Users/mcros/Nextcloud/org/_todo.org" org-mode)
((def-buffer "_todo.org" "c:/Users/mcros/Nextcloud/org/_todo.org" org-mode)
(def-buffer "_index.org" "c:/Users/mcros/Nextcloud/org/_index.org" org-mode)
(def-buffer "_index_phone.org" "c:/Users/mcros/Nextcloud/org/_index_phone.org" org-mode)
(def-buffer "_health.org" "c:/Users/mcros/Nextcloud/org/health/_health.org" org-mode)
(def-buffer "health_houdini.org" "c:/Users/mcros/Nextcloud/org/health/health_houdini.org" org-mode)
@ -20,13 +20,13 @@
(min-pixel-height-safe . 20)
(min-pixel-width-safe . 20))
leaf
(pixel-width . 1262)
(pixel-height . 1262)
(total-width . 126)
(total-height . 63)
(pixel-width . 837)
(pixel-height . 700)
(total-width . 83)
(total-height . 35)
(normal-height . 1.0)
(normal-width . 1.0)
(buffer "*Org Agenda*"
(buffer "_todo.org"
(selected . t)
(hscroll . 0)
(fringes 8 8 nil nil)
@ -34,7 +34,7 @@
(scroll-bars nil 3 t nil 0 t nil)
(vscroll . 0)
(dedicated)
(point . 1142)
(point . 1)
(start . 1))
(prev-buffers
("*Org Agenda*" 1 1142)

View File

@ -26,7 +26,7 @@
(total-height . 63)
(normal-height . 1.0)
(normal-width . 1.0)
(buffer "*Messages*"
(buffer "*Org Agenda*"
(selected . t)
(hscroll . 0)
(fringes 8 8 nil nil)
@ -34,7 +34,7 @@
(scroll-bars nil 3 t nil 0 t nil)
(vscroll . 0)
(dedicated)
(point . 521)
(point . 1142)
(start . 1))
(prev-buffers
("*Org Agenda*" 1 1142)

View File

@ -7,67 +7,37 @@
(def-buffer "health_houdini.org" "c:/Users/mcros/Nextcloud/org/health/health_houdini.org" org-mode)
(def-buffer "health_mike.org" "c:/Users/mcros/Nextcloud/org/health/health_mike.org" org-mode))
(def-wconf
(((min-height . 8)
(((min-height . 4)
(min-width . 10)
(min-height-ignore . 6)
(min-height-ignore . 3)
(min-width-ignore . 6)
(min-height-safe . 2)
(min-height-safe . 1)
(min-width-safe . 2)
(min-pixel-height . 160)
(min-pixel-height . 80)
(min-pixel-width . 100)
(min-pixel-height-ignore . 120)
(min-pixel-height-ignore . 60)
(min-pixel-width-ignore . 60)
(min-pixel-height-safe . 40)
(min-pixel-height-safe . 20)
(min-pixel-width-safe . 20))
vc
(pixel-width . 837)
(pixel-height . 700)
(total-width . 83)
(total-height . 35)
leaf
(pixel-width . 1262)
(pixel-height . 1262)
(total-width . 126)
(total-height . 63)
(normal-height . 1.0)
(normal-width . 1.0)
(combination-limit)
(leaf
(pixel-width . 837)
(pixel-height . 309)
(total-width . 83)
(total-height . 15)
(normal-height . 0.4414285714285714)
(normal-width . 1.0)
(buffer "*Org Agenda*"
(selected)
(hscroll . 0)
(fringes 8 8 nil nil)
(margins nil)
(scroll-bars nil 3 t nil 0 t nil)
(vscroll . 0)
(dedicated . "t")
(point . 1)
(start . 1))
(prev-buffers
("*scratch*" 1 1)))
(leaf
(last . t)
(pixel-width . 837)
(pixel-height . 391)
(total-width . 83)
(total-height . 20)
(normal-height . 0.5585714285714286)
(normal-width . 1.0)
(buffer "*Warnings*"
(selected . t)
(hscroll . 0)
(fringes 8 8 nil nil)
(margins nil)
(scroll-bars nil 3 t nil 0 t nil)
(vscroll . 0)
(dedicated)
(point . 108)
(start . 1))
(prev-buffers
("_index.org" 1 1)
("_todo.org" 1 1)
("_index_phone.org" 1 1)
("*Org Agenda*" 1 1)))))
(buffer "*Messages*"
(selected . t)
(hscroll . 0)
(fringes 8 8 nil nil)
(margins nil)
(scroll-bars nil 3 t nil 0 t nil)
(vscroll . 0)
(dedicated)
(point . 521)
(start . 1))
(prev-buffers
("*Org Agenda*" 1 1142)
("*scratch*" 1 1))))
(def-params nil)
t nil nil))