[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pabbrev ea437a2210 02/15: Refactored, if->when, inline
From: |
Phillip Lord |
Subject: |
[elpa] externals/pabbrev ea437a2210 02/15: Refactored, if->when, inline |
Date: |
Tue, 6 Feb 2024 11:40:52 -0500 (EST) |
branch: externals/pabbrev
commit ea437a22101a9f51f86854e85a1a72e9188e6478
Author: Arthur Miller <arthur.miller@live.com>
Commit: Arthur Miller <arthur.miller@live.com>
Refactored, if->when, inline
---
pabbrev.el | 541 +++++++++++++++++++++++++++----------------------------------
1 file changed, 239 insertions(+), 302 deletions(-)
diff --git a/pabbrev.el b/pabbrev.el
index 1e30d33571..267c547075 100644
--- a/pabbrev.el
+++ b/pabbrev.el
@@ -346,6 +346,10 @@ I'm not telling you which version, I prefer."
(defvar pabbrev--dstr)
(defvar pabbrev--ref1)
+(defvar pabbrev-short-idle-timer nil
+ "Timer which adds a few words.
+See `pabbrev-long-idle-timer'.")
+
(defmacro pabbrev-working-status-forms (message donestr &rest forms)
"Contain a block of code during which a working status is shown."
`(let ((pabbrev--msg ,message) (pabbrev--dstr ,donestr)
@@ -355,11 +359,11 @@ I'm not telling you which version, I prefer."
(defun pabbrev-working-status (&optional percent &rest args)
"Called within the macro `pabbrev-working-status-forms', show the status."
(message "%s%s" (apply 'format pabbrev--msg args)
- (if (eq percent t) (concat "... " pabbrev--dstr)
+ (if (eq percent t)
+ (concat "... " pabbrev--dstr)
(format "... %3d%%"
(or percent
- (floor (* 100.0 (/ (float (point))
- (point-max)))))))))
+ (floor (* 100.0 (/ (float (point)) (point-max)))))))))
;; stolen from font-lock!
(if (featurep 'xemacs)
@@ -445,6 +449,19 @@ I'm not telling you which version, I prefer."
(defvar pabbrev-prefix-hash-modes nil
"List of modes with associated prefix dictionaries.")
+(defvar pabbrev-long-idle-timer nil
+ "Timer which adds whole buffer.
+There are two idle timers which run for function `pabbrev-mode'. This
+one doesn't start for a while, but once it has will work its way
+through the whole buffer. In prints out a message to say what its
+doing, and stops on user input. The variable
+`pabbrev-short-idle-timer' is the other.
+The idea here is that the short timer will pick up most of the recent
+changes, and will not bother the user. The long timer will slowly
+gather up the whole buffer, telling the user what it is doing, in case
+it takes up too much processor. If this happened after a second it
+would be irritating in the extreme.")
+
(defmacro pabbrev-save-buffer-modified-p (&rest body)
"Eval BODY without affected buffer modification status."
`(with-silent-modifications
@@ -455,8 +472,7 @@ I'm not telling you which version, I prefer."
(let((hash (get major-mode 'pabbrev-usage-hash)))
(unless hash
(put major-mode 'pabbrev-usage-hash
- (setq hash
- (make-hash-table :test 'equal)))
+ (setq hash (make-hash-table :test 'equal)))
(push major-mode pabbrev-usage-hash-modes))
hash))
@@ -479,8 +495,7 @@ I'm not telling you which version, I prefer."
(let((hash (get major-mode 'pabbrev-prefix-hash)))
(unless hash
(put major-mode 'pabbrev-prefix-hash
- (setq hash
- (make-hash-table :test 'equal)))
+ (setq hash (make-hash-table :test 'equal)))
(push major-mode pabbrev-prefix-hash-modes))
hash))
@@ -492,21 +507,17 @@ This is a function internal to the data structures. The
(gethash
;; look for word usage cons we need a cons, but the last
;; value is irrelevant.
- word
- (pabbrev-get-usage-hash))))
+ word (pabbrev-get-usage-hash))))
;; so now we have cons, or nil
(if value
;; increment occurences
- (setcdr
- value (+ 1 (cdr value)))
+ (setcdr value (+ 1 (cdr value)))
;; we have no so make is
- (setq value
- (cons word 1)))
+ (setq value (cons word 1)))
;; so now we the cons cell for sure
;; possible we should do this above, as I think it only needs
;; doing for a new cons.
- (puthash word value (pabbrev-get-usage-hash))
- value))
+ (puthash word value (pabbrev-get-usage-hash)) value))
(defun pabbrev-add-word-cons-with-prefix (prefix conscell)
"Add a word usage, and a PREFIX.
@@ -516,23 +527,19 @@ returned from `pabbrev-add-word-usage', while PREFIX
should be a
prefix of the from the cons cell."
(let
;; this should be an alist or nil
- ((value (gethash prefix
- (pabbrev-get-prefix-hash))))
+ ((value (gethash prefix (pabbrev-get-prefix-hash))))
(if value
;; so we have an alist. Has our word been added to this alist
;; before? If not, do so. If it has been added, then it will
;; have been updated with the addition of the word
- (if (not
- (member conscell value))
- (setq value (cons conscell value)))
+ (unless (member conscell value)
+ (setq value (cons conscell value)))
;; nothing in there, so create an alist with
;; a single element
(setq value (list conscell)))
;; so we now have the value alist...sort it and store it back in
;; the hash
- (puthash prefix
- (pabbrev-sort-alist value)
- (pabbrev-get-prefix-hash))))
+ (puthash prefix (pabbrev-sort-alist value) (pabbrev-get-prefix-hash))))
(defun pabbrev-sort-alist(alist)
;; this sort is bit poor. It should be possible to do this in less
@@ -557,20 +564,17 @@ prefix of the from the cons cell."
;; time is spent in placing on the "been here" overlays....
(sort alist
;;'pabbrev-comparitor-function))
- (lambda(a b)
- (> (cdr a) (cdr b)))))
+ (lambda(a b) (> (cdr a) (cdr b)))))
(defsubst pabbrev-comparitor-function(a b)
(> (cdr a) (cdr b)))
(defun pabbrev-add-word (word)
"Add the usage of a WORD to the current dictionary."
- (let ((conscell
- (pabbrev-add-word-usage word)))
+ (let ((conscell (pabbrev-add-word-usage word)))
(dotimes (i (- (length word) 1))
(pabbrev-add-word-cons-with-prefix
- (substring word 0 (1+ i))
- conscell))))
+ (substring word 0 (1+ i)) conscell))))
(defun pabbrev-fetch-all-suggestions-for-prefix(prefix)
"Return the suggestions for a given PREFIX.
@@ -596,6 +600,20 @@ it's ordering is part of the core data structures"
map)
"Keymap for pabbrev-minor-mode.")
+(defsubst pabbrev-bounds-of-thing-at-point()
+ "Get the bounds of the thing at point"
+ (bounds-of-thing-at-point pabbrev-thing-at-point-constituent))
+
+(defsubst pabbrev-thing-at-point()
+ "Get thing at point."
+ (when-let ((bounds (pabbrev-bounds-of-thing-at-point)))
+ (buffer-substring-no-properties (car bounds) (cdr bounds))))
+
+(defsubst pabbrev-ensure-idle-timer()
+ (unless nil
+ (unless (and pabbrev-short-idle-timer pabbrev-long-idle-timer)
+ (pabbrev-start-idle-timer))))
+
;; XEmacs has synced to newest easy-mmode now.
;;(if (not (featurep 'xemacs))
;;;###autoload
@@ -671,31 +689,22 @@ not a minibuffer."
((pabbrev-scavenge-some-chunk-size 0))
(pabbrev-mode))))
-(defvar pabbrev-marker nil
+(defvar-local pabbrev-marker nil
"Location of current insertion, or nil.
This variable is not actually a marker, but a cons of
start and end positions")
-(make-variable-buffer-local 'pabbrev-marker)
-(defvar pabbrev-expansion nil
+(defvar-local pabbrev-expansion nil
"Currently displayed expansion, or nil.")
-(make-variable-buffer-local 'pabbrev-expansion)
-(defvar pabbrev-expansion-suggestions nil
+(defvar-local pabbrev-expansion-suggestions nil
"Current expansion suggestions, or nil.")
-(make-variable-buffer-local 'pabbrev-expansion-suggestions)
-(defvar pabbrev-marker-last-expansion nil
+(defvar-local pabbrev-marker-last-expansion nil
"Marks where the last possible expansion was.")
-(make-variable-buffer-local 'pabbrev-marker-last-expansion)
;;(defun test()(interactive)(let ((last-command
'self-insert-command))(pabbrev-post-command-hook)))
-(defsubst pabbrev-bounds-of-thing-at-point()
- "Get the bounds of the thing at point"
- (bounds-of-thing-at-point
- pabbrev-thing-at-point-constituent))
-
;;(defun test()
;; (interactive)
;; (pabbrev-insert-suggestion
@@ -723,7 +732,7 @@ This function is normally run off the `post-command-hook'."
(let ((word (pabbrev-thing-at-point))
(bounds (pabbrev-bounds-of-thing-at-point))
(suggestions))
- (if (and
+ (when (and
;; last command was a symbol
;; PWL last-command to this-command
(symbolp this-command)
@@ -737,9 +746,8 @@ This function is normally run off the `post-command-hook'."
(= (point) (cdr bounds))
;; and we have some suggestions.
(setq suggestions (pabbrev-fetch-all-suggestions-for-prefix
word)))
- (progn
- (pabbrev-insert-suggestion word suggestions)
- (pabbrev-post-command-check-movement))))))
+ (pabbrev-insert-suggestion word suggestions)
+ (pabbrev-post-command-check-movement)))))
(error
(pabbrev-command-hook-fail err "post"))))
@@ -809,38 +817,36 @@ anything. Toggling it off, and then on again will usually
restore functionality.
(select-window (get-buffer-window "*pabbrev-fail*"))
(error "Error in pabbrev-mode"))
+(defsubst pabbrev-debug-get-buffer()
+ (get-buffer-create "*pabbrev-debug"))
+
(defun pabbrev-marker-last-expansion()
"Fetch marker for last offered expansion."
(or pabbrev-marker-last-expansion
(setq pabbrev-marker-last-expansion
- (set-marker (make-marker)
- (point) (current-buffer)))))
+ (set-marker (make-marker) (point) (current-buffer)))))
(defsubst pabbrev-update-marker()
- (set-marker (pabbrev-marker-last-expansion)
- (point) (current-buffer)))
+ (set-marker (pabbrev-marker-last-expansion) (point) (current-buffer)))
(defvar pabbrev-debug-enabled nil)
(defmacro pabbrev-debug-message(&rest body)
- `(if pabbrev-debug-enabled
- (let ((insert
- (concat (format ,@body) "\n")))
- (with-current-buffer
- (pabbrev-debug-get-buffer)
- (goto-char (point-max))
- (insert insert)
- (pabbrev-debug-frame-scroll)))))
+ `(when pabbrev-debug-enabled
+ (let ((insert (concat (format ,@body) "\n")))
+ (with-current-buffer (pabbrev-debug-get-buffer)
+ (goto-char (point-max))
+ (insert insert)
+ (pabbrev-debug-frame-scroll)))))
(defun pabbrev-post-command-check-movement()
(let ((distance
(abs (- (point) (marker-position
(pabbrev-marker-last-expansion))))))
- (if (> distance pabbrev-marker-distance-before-scavenge)
- ;; we have moved a lot in the buffer
- (progn
- (pabbrev-debug-message "Scavenge due to buffer marker")
- (pabbrev-scavenge-some)
- (pabbrev-update-marker)))))
+ (when (> distance pabbrev-marker-distance-before-scavenge)
+ ;; we have moved a lot in the buffer
+ (pabbrev-debug-message "Scavenge due to buffer marker")
+ (pabbrev-scavenge-some)
+ (pabbrev-update-marker))))
(defun pabbrev-set-overlay(start end count)
"Move overlay to START END location."
@@ -850,7 +856,8 @@ anything. Toggling it off, and then on again will usually
restore functionality.
;; it crashes XEmacs...well I never....
(make-overlay 1 1)))
(overlay-put pabbrev-overlay 'face
- (if (> count 1) 'pabbrev-suggestions-face
+ (if (> count 1)
+ 'pabbrev-suggestions-face
'pabbrev-single-suggestion-face))
(move-overlay pabbrev-overlay start end (current-buffer)))
@@ -861,39 +868,37 @@ The suggestion should start with PREFIX, and be entered
at point."
(let* ((suggestion
(if (not pabbrev-minimal-expansion-p)
(car (car suggestions))
- (try-completion "" suggestions))))
- (let ((expansion
+ (try-completion "" suggestions)))
+ (expansion
(if suggestion
- (substring suggestion
- (length prefix))
+ (substring suggestion (length prefix))
""))
- (end (point)))
- (when (< 0 (length expansion))
- ;; Add the abbreviation to the buffer.
- (setq
- pabbrev-expansion expansion
- pabbrev-expansion-suggestions suggestions)
- (if (featurep 'xemacs)
- (save-excursion
- (pabbrev-save-buffer-modified-p
- (insert
- "[" expansion "]" )
- ;; store everything. Most importantly the pabbrev-marker!
- (setq pabbrev-marker (cons end (point)))
- (let ((point-1 (- (point) 1)))
- (pabbrev-set-overlay
- (- point-1 (length expansion)) point-1
- (length suggestions)))))
- (pabbrev-set-overlay (point) (point)
- (length suggestions))
- (setq pabbrev-marker (cons (point) (point)))
- (overlay-put pabbrev-overlay
- 'after-string
- (concat
- (propertize "[" 'cursor 1)
- (propertize expansion
- 'face (overlay-get pabbrev-overlay 'face))
- "]")))))))
+ (end (point)))
+ (when (< 0 (length expansion))
+ ;; Add the abbreviation to the buffer.
+ (setq pabbrev-expansion expansion
+ pabbrev-expansion-suggestions suggestions)
+ (if (featurep 'xemacs)
+ (save-excursion
+ (pabbrev-save-buffer-modified-p
+ (insert
+ "[" expansion "]" )
+ ;; store everything. Most importantly the pabbrev-marker!
+ (setq pabbrev-marker (cons end (point)))
+ (let ((point-1 (- (point) 1)))
+ (pabbrev-set-overlay
+ (- point-1 (length expansion)) point-1
+ (length suggestions)))))
+ (pabbrev-set-overlay (point) (point)
+ (length suggestions))
+ (setq pabbrev-marker (cons (point) (point)))
+ (overlay-put pabbrev-overlay
+ 'after-string
+ (concat
+ (propertize "[" 'cursor 1)
+ (propertize expansion
+ 'face (overlay-get pabbrev-overlay 'face))
+ "]"))))))
(defvar pabbrev-last-expansion-suggestions nil
"Cached alternative suggestions from the last expansion.")
@@ -903,15 +908,15 @@ The suggestion should start with PREFIX, and be entered
at point."
(defun pabbrev-call-previous-tab-binding ()
"Call the function normally associated with [tab]."
(let ((prev-binding (pabbrev-get-previous-binding)))
- (if (and (fboundp prev-binding)
- (not (eq prev-binding 'pabbrev-expand-maybe)))
- (let ((last-command (if (eq last-command this-command)
- prev-binding
- last-command))
- (this-command prev-binding))
- (if (eq 'self-insert-command prev-binding)
- (self-insert-command 1)
- (funcall prev-binding))))))
+ (when (and (fboundp prev-binding)
+ (not (eq prev-binding 'pabbrev-expand-maybe)))
+ (let ((last-command (if (eq last-command this-command)
+ prev-binding
+ last-command))
+ (this-command prev-binding))
+ (if (eq 'self-insert-command prev-binding)
+ (self-insert-command 1)
+ (funcall prev-binding))))))
;; (defun pabbrev-call-previous-tab-binding ()
;; "Call the function normally associated with [tab]."
@@ -920,7 +925,6 @@ The suggestion should start with PREFIX, and be entered at
point."
;; (not (eq prev-binding 'pabbrev-expand-maybe)))
;; (funcall prev-binding))))
-
(defun pabbrev-expand-maybe(uarg)
"Call appropriate expansion command based on whether minimal or
full expansion is desired. If there is no expansion the command
@@ -959,9 +963,8 @@ UARG is the prefix argument."
(pabbrev-suggestions-goto-buffer pabbrev-last-expansion-suggestions)
(pabbrev-call-previous-tab-binding)))
(pabbrev-expansion
- (progn
- (setq pabbrev-last-expansion-suggestions pabbrev-expansion-suggestions)
- (pabbrev-expand)))
+ (setq pabbrev-last-expansion-suggestions pabbrev-expansion-suggestions)
+ (pabbrev-expand))
(t (pabbrev-call-previous-tab-binding))))
;; (setq pabbrev-minimal-expansion-p nil)
@@ -990,14 +993,11 @@ The command `pabbrev-show-previous-binding' prints this
out."
(this-command-keys)
(this-command-keys-vector))))
(cond
- ((or (equal tckv [tab])
- (equal tckv [9]))
+ ((or (equal tckv [tab]) (equal tckv [9]))
(or (key-binding [tab]) (key-binding "\t")))
- ((or (equal tckv [return])
- (equal tckv [32]))
+ ((or (equal tckv [return]) (equal tckv [32]))
(or (key-binding [return]) (key-binding "\n")))
- (t
- (key-binding tckv))))))
+ (t (key-binding tckv))))))
;; ;; This is the original and satisfying solution
;; (key-binding (this-command-keys))))
@@ -1057,9 +1057,8 @@ The command `pabbrev-show-previous-binding' prints this
out."
(defun pabbrev-suggestions-delete-window()
"Delete the suggestions window."
(interactive)
- (unless
- (or pabbrev-mode
- (eq (buffer-name) " *pabbrev suggestions*"))
+ (unless (or pabbrev-mode
+ (eq (buffer-name) " *pabbrev suggestions*"))
(delete-window (get-buffer-window " *pabbrev suggestions*"))
(set-window-configuration pabbrev-window-configuration)))
@@ -1103,14 +1102,12 @@ The command `pabbrev-show-previous-binding' prints this
out."
(defun pabbrev-suggestions-buffer(suggestions _prefix)
"Form the suggestions buffer."
(with-output-to-temp-buffer " *pabbrev suggestions*"
- (setq pabbrev-suggestions-from-buffer (current-buffer))
- (setq pabbrev-suggestions-best-suggestion
- (car suggestions))
- (setq pabbrev-suggestions-done-suggestions
- (pabbrev-suggestions-limit-alpha-sort suggestions))
- (setq suggestions pabbrev-suggestions-done-suggestions)
- (let
- ((window-width (- (window-width) 1)))
+ (setq pabbrev-suggestions-from-buffer (current-buffer)
+ pabbrev-suggestions-best-suggestion (car suggestions)
+ pabbrev-suggestions-done-suggestions
+ (pabbrev-suggestions-limit-alpha-sort suggestions)
+ suggestions pabbrev-suggestions-done-suggestions)
+ (let ((window-width (- (window-width) 1)))
(with-current-buffer
(get-buffer " *pabbrev suggestions*")
(pabbrev-suggestions-setup)`
@@ -1122,32 +1119,32 @@ The command `pabbrev-show-previous-binding' prints this
out."
(concat
"Best Match: " (car pabbrev-suggestions-best-suggestion)
"\n"))
- (if suggestions
- (cl-loop for i from 0 to 9 do
- ;; are we less than the suggestions
- (if (< i (length suggestions))
- (progn
- (goto-char (point-max))
- ;; insert all the suggestions
- (let ((next-suggestion
- (concat
- (number-to-string i)
- ") "
- (car (nth i suggestions)) " " ))
- (line-length
- (- (line-end-position)
(line-beginning-position))))
- ;; if well. are not on the first suggestion,
- (if (and (> i 0)
- ;; and the line will be too long
- (< window-width
- (+ line-length (length
next-suggestion))))
- ;; add a new line.
- (princ "\n"))
- (princ next-suggestion)
- (let ((start (- (point) (length
next-suggestion))))
- (overlay-put
- (make-overlay start (+ 2 start))
- 'face 'pabbrev-suggestions-label-face))))))))))
+ (when suggestions
+ (cl-loop for i from 0 to 9 do
+ ;; are we less than the suggestions
+ (when (< i (length suggestions))
+ (goto-char (point-max))
+ ;; insert all the suggestions
+
+ (let ((next-suggestion
+ (concat
+ (number-to-string i)
+ ") "
+ (car (nth i suggestions)) " " ))
+ (line-length
+ (- (line-end-position) (line-beginning-position))))
+ ;; if well. are not on the first suggestion,
+ (when (and (> i 0)
+ ;; and the line will be too long
+ (< window-width
+ (+ line-length (length next-suggestion))))
+ ;; add a new line.
+ (princ "\n"))
+ (princ next-suggestion)
+ (let ((start (- (point) (length next-suggestion))))
+ (overlay-put
+ (make-overlay start (+ 2 start))
+ 'face 'pabbrev-suggestions-label-face)))))))))
(shrink-window-if-larger-than-buffer (get-buffer-window " *pabbrev
suggestions*")))
(defun pabbrev-suggestions-subseq(sequence from to)
@@ -1170,7 +1167,7 @@ It crashes under the same circumstances. Yeech."
(defvar pabbrev-select-mode-map
(let ((map (make-sparse-keymap)))
(cl-loop for i from ?! to ?~ do
- (define-key map (char-to-string i) 'pabbrev-noop))
+ (define-key map (char-to-string i) 'pabbrev-noop))
(define-key map "\t" 'pabbrev-suggestions-select-default)
(define-key map [delete] 'pabbrev-suggestions-delete)
(define-key map "\C-?" 'pabbrev-suggestions-delete)
@@ -1178,9 +1175,8 @@ It crashes under the same circumstances. Yeech."
(define-key map " " 'pabbrev-suggestions-delete-window)
(define-key map "q" 'pabbrev-suggestions-delete-window)
;; Define all the standard insert commands.
- (cl-loop for i from 0 to 9 do
- (define-key map
- (number-to-string i) 'pabbrev-suggestions-select))
+ (dotimes (i 10)
+ (define-key map (number-to-string i) 'pabbrev-suggestions-select))
map))
(define-derived-mode pabbrev-select-mode fundamental-mode ;Use special-mode?
@@ -1200,15 +1196,13 @@ self inserting commands."
(defun pabbrev-suggestions-select-default()
"Select the most commonly occuring string."
(interactive)
- (if pabbrev-suggestions-best-suggestion
- (pabbrev-suggestions-insert
- (car pabbrev-suggestions-best-suggestion))))
+ (when pabbrev-suggestions-best-suggestion
+ (pabbrev-suggestions-insert (car pabbrev-suggestions-best-suggestion))))
(defun pabbrev-suggestions-delete()
"Delete the last suggestion."
(interactive)
- (pabbrev-suggestions-insert
- pabbrev-expand-previous-word))
+ (pabbrev-suggestions-insert pabbrev-expand-previous-word))
(defun pabbrev-suggestions-minimum()
"Select the maximally occuring substring."
@@ -1224,27 +1218,21 @@ self inserting commands."
(with-current-buffer
pabbrev-suggestions-from-buffer
(let ((bounds (pabbrev-bounds-of-thing-at-point)))
- (progn
- (delete-region (car bounds) (cdr bounds))
- (insert insertion)
- (setq point (point)))))
+ (delete-region (car bounds) (cdr bounds))
+ (insert insertion)
+ (setq point (point))))
(pabbrev-suggestions-delete-window)
- (if point
- (goto-char point))))
+ (when point (goto-char point))))
(defun pabbrev-suggestions-select(&optional index)
"Select one of the numbered suggestions."
(interactive)
(let ((insert-index
(or index
- (string-to-number
- (char-to-string last-command-event)))))
- (if (< insert-index
- (length pabbrev-suggestions-done-suggestions))
- (pabbrev-suggestions-insert
- (car
- (nth insert-index pabbrev-suggestions-done-suggestions))))))
-
+ (string-to-number (char-to-string last-command-event)))))
+ (when (< insert-index (length pabbrev-suggestions-done-suggestions))
+ (pabbrev-suggestions-insert
+ (car (nth insert-index pabbrev-suggestions-done-suggestions))))))
;; These functions define movement around the buffer, which
;; determines what pabbrev considers to be a "word"
@@ -1253,13 +1241,6 @@ self inserting commands."
(interactive)
(forward-thing pabbrev-thing-at-point-constituent number))
-(defun pabbrev-thing-at-point()
- "Get thing at point."
- (let ((bounds (pabbrev-bounds-of-thing-at-point)))
- (if bounds
- (buffer-substring-no-properties
- (car bounds) (cdr bounds)))))
-
;; These functions deal with scavenging word usage from the buffer,
;; which are then added to the dictionary.
(defun pabbrev-bounds-marked-p (start end)
@@ -1268,29 +1249,27 @@ self inserting commands."
(let ((retn))
(cl-do ((i start (1+ i)))
((> i end))
- (if
- (setq retn
- (get-text-property i 'pabbrev-added))
- (setq i end)))
+ (when (setq retn (get-text-property i 'pabbrev-added))
+ (setq i end)))
retn)))
(defun pabbrev-mark-add-word (bounds)
"Add word in BOUNDS as abbreviation, and mark the buffer."
- (if bounds
- (let ((start (car bounds))
- (end (cdr bounds)))
- (unless
- ;; is this word or part of it already added?
- (pabbrev-bounds-marked-p start end)
- ;; mark the word visibly as well.
- (pabbrev-debug-display start end)
- ;; set a property so that we know what we have done.
- (pabbrev-save-buffer-modified-p
- (add-text-properties start end
- '(pabbrev-added t)))
- ;; and add the word to the system.
- (pabbrev-add-word
- (buffer-substring-no-properties start end))))))
+ (when bounds
+ (let ((start (car bounds))
+ (end (cdr bounds)))
+ (unless
+ ;; is this word or part of it already added?
+ (pabbrev-bounds-marked-p start end)
+ ;; mark the word visibly as well.
+ (pabbrev-debug-display start end)
+ ;; set a property so that we know what we have done.
+ (pabbrev-save-buffer-modified-p
+ (add-text-properties start end
+ '(pabbrev-added t)))
+ ;; and add the word to the system.
+ (pabbrev-add-word
+ (buffer-substring-no-properties start end))))))
(defun pabbrev-scavenge-some()
"Gather some words up from around point"
@@ -1299,8 +1278,7 @@ self inserting commands."
;; move somewhat away from point, as this is likely to not contain
;; complete words.
(pabbrev-forward-thing -2)
- (pabbrev-scavenge-words -1
- (* 2 pabbrev-scavenge-some-chunk-size))
+ (pabbrev-scavenge-words -1 (* 2 pabbrev-scavenge-some-chunk-size))
(save-excursion
(pabbrev-forward-thing 2)
(pabbrev-scavenge-words 1 pabbrev-scavenge-some-chunk-size))))
@@ -1316,12 +1294,10 @@ self inserting commands."
(save-excursion
(goto-char (point-min))
(while (pabbrev-forward-thing)
-
(let* ((bounds (pabbrev-bounds-of-thing-at-point))
(start (car bounds))
(stop (cdr bounds)))
- (unless
- (pabbrev-bounds-marked-p start stop)
+ (unless (pabbrev-bounds-marked-p start stop)
(pabbrev-add-word
(buffer-substring-no-properties start stop)))))
@@ -1329,8 +1305,7 @@ self inserting commands."
(pabbrev-get-usage-dictionary-size)
(pabbrev-get-total-usages-dictionary))
(pabbrev-save-buffer-modified-p
- (add-text-properties (point-min) (point-max)
- '(pabbrev-added t)))
+ (add-text-properties (point-min) (point-max) '(pabbrev-added t)))
(message "pabbrev fast scavenging buffer...done.")))
(defun pabbrev-scavenge-buffer()
@@ -1352,10 +1327,8 @@ self inserting commands."
"Scavenge words from current buffer, starting from point.
DIRECTION is in which direction we should work,
NUMBER is how many words we should try to scavenge"
- (if (not direction)
- (setq direction 1))
- (if (not number)
- (setq number 20))
+ (unless direction (setq direction 1))
+ (unless number (setq number 20))
(save-excursion
(dotimes (_ number)
(pabbrev-forward-thing direction)
@@ -1363,33 +1336,10 @@ NUMBER is how many words we should try to scavenge"
(pabbrev-bounds-of-thing-at-point)))
(point)))
-(defvar pabbrev-long-idle-timer nil
- "Timer which adds whole buffer.
-There are two idle timers which run for function `pabbrev-mode'. This
-one doesn't start for a while, but once it has will work its way
-through the whole buffer. In prints out a message to say what its
-doing, and stops on user input. The variable
-`pabbrev-short-idle-timer' is the other.
-The idea here is that the short timer will pick up most of the recent
-changes, and will not bother the user. The long timer will slowly
-gather up the whole buffer, telling the user what it is doing, in case
-it takes up too much processor. If this happened after a second it
-would be irritating in the extreme.")
-
-(defvar pabbrev-short-idle-timer nil
- "Timer which adds a few words.
-See `pabbrev-long-idle-timer'.")
-
-(defun pabbrev-ensure-idle-timer()
- (unless nil
- (if (not (and pabbrev-short-idle-timer
- pabbrev-long-idle-timer))
- (pabbrev-start-idle-timer))))
-
(defun pabbrev-start-idle-timer()
(setq pabbrev-long-idle-timer
- (run-with-idle-timer 5 t 'pabbrev-idle-timer-function))
- (setq pabbrev-short-idle-timer
+ (run-with-idle-timer 5 t 'pabbrev-idle-timer-function)
+ pabbrev-short-idle-timer
(run-with-idle-timer 1 t 'pabbrev-short-idle-timer)))
;;(setq pabbrev-disable-timers t)
@@ -1405,14 +1355,14 @@ See `pabbrev-long-idle-timer'.")
(or buffer (current-buffer))
;; remember which buffer we have just looked at.
(setq pabbrev-timer-buffer (current-buffer))
- (if (and pabbrev-mode (not pabbrev-disable-timers))
- (progn
- (pabbrev-debug-message "running short idle timer")
- ;;(message "Running short timer in %s" (current-buffer))
- (pabbrev-scavenge-some)
- (pabbrev-debug-message "Dictionary size %s total usage %s"
- (pabbrev-get-usage-dictionary-size)
- (pabbrev-get-total-usages-dictionary))))))
+ (when (and pabbrev-mode (not pabbrev-disable-timers))
+ (pabbrev-debug-message "running short idle timer")
+ ;;(message "Running short timer in %s" (current-buffer))
+
+ (pabbrev-scavenge-some)
+ (pabbrev-debug-message "Dictionary size %s total usage %s"
+ (pabbrev-get-usage-dictionary-size)
+ (pabbrev-get-total-usages-dictionary)))))
(defun pabbrev-idle-timer-function(&optional buffer)
;; so this only works on the current buffer. Might want to scavenge
@@ -1436,12 +1386,11 @@ If it up too much processor power, see
`pabbrev-scavenge-some-chunk-size'."
(forward-complete nil)
(backward-complete nil)
(repeat t))
- (if pabbrev-idle-timer-verbose
- (message "pabbrev scavenging..."))
+ (when pabbrev-idle-timer-verbose
+ (message "pabbrev scavenging..."))
(pabbrev-debug-message "running idle timer at %s" (point))
- (while
- (and repeat
- (not (and forward-complete backward-complete)))
+ (while (and repeat
+ (not (and forward-complete backward-complete)))
(save-excursion
(unless backward-complete
(goto-char backward-marker)
@@ -1464,15 +1413,15 @@ If it up too much processor power, see
`pabbrev-scavenge-some-chunk-size'."
(pabbrev-get-usage-dictionary-size)
(pabbrev-get-total-usages-dictionary))
- (if pabbrev-idle-timer-verbose
- (message "pabbrev scavenging (%s words %s buffer)..."
(pabbrev-get-usage-dictionary-size)
- (buffer-name (current-buffer))))
+ (when pabbrev-idle-timer-verbose
+ (message "pabbrev scavenging (%s words %s buffer)..."
+ (pabbrev-get-usage-dictionary-size)
+ (buffer-name (current-buffer))))
(setq repeat (sit-for 0.1)))
- (if pabbrev-idle-timer-verbose
- (progn
- (message "pabbrev scavenging...done")
- (sit-for 2)
- (message nil)))))
+ (when pabbrev-idle-timer-verbose
+ (message "pabbrev scavenging...done")
+ (sit-for 2)
+ (message nil))))
(defun pabbrev-shut-up()
"Switch off verbose messages..."
@@ -1486,32 +1435,27 @@ If it up too much processor power, see
`pabbrev-scavenge-some-chunk-size'."
;;(setq pabbrev-debug-enabled t)
(defvar pabbrev-debug-enabled nil)
-(defun pabbrev-debug-get-buffer()
- (get-buffer-create "*pabbrev-debug"))
-
(defun pabbrev-debug()
(interactive)
(pabbrev-debug-frame)
(setq pabbrev-debug-enabled t))
(defvar pabbrev-debug-frame nil)
-(defun pabbrev-debug-frame()
+(defun pabbrev-debug-frame ()
(interactive)
- (if (not pabbrev-debug-frame)
- (progn
- (setq pabbrev-debug-frame
- (make-frame '((width . 30)
- (height . 30))))
- (select-frame pabbrev-debug-frame)
- (switch-to-buffer (pabbrev-debug-get-buffer)))))
-
-(defun pabbrev-debug-frame-scroll()
+ (when (not pabbrev-debug-frame)
+ (setq pabbrev-debug-frame
+ (make-frame '((width . 30)
+ (height . 30))))
+ (select-frame pabbrev-debug-frame)
+ (switch-to-buffer (pabbrev-debug-get-buffer))))
+
+(defun pabbrev-debug-frame-scroll ()
(save-excursion
- (if pabbrev-debug-frame
- (progn
- (select-frame pabbrev-debug-frame)
- (switch-to-buffer (pabbrev-debug-get-buffer))
- (goto-char (point-max))))))
+ (when pabbrev-debug-frame
+ (select-frame pabbrev-debug-frame)
+ (switch-to-buffer (pabbrev-debug-get-buffer))
+ (goto-char (point-max)))))
;;(setq pabbrev-debug-display t)
(defvar pabbrev-debug-display nil
@@ -1520,8 +1464,8 @@ This looks very ugly. Note that this only shows newly
added words. Use
`pabbrev-debug-remove-properties' to clear this invisible markers. Use
`pabbrev-debug-show-all-properties' to show existing markers.")
-(defun pabbrev-debug-display(start end)
- (if pabbrev-debug-display
+(defun pabbrev-debug-display (start end)
+ (when pabbrev-debug-display
(overlay-put
(make-overlay start end)
'face 'pabbrev-debug-display-label-face)))
@@ -1538,12 +1482,10 @@ This looks very ugly. Note that this only shows newly
added words. Use
(pabbrev-debug-remove-properties)
(mapcar
(lambda(overlay)
- (if
- (eq 'pabbrev-debug-display-label-face
- (overlay-get overlay 'face))
- (delete-overlay overlay)))
- (overlays-in
- (point-min) (point-max))))
+ (when (eq 'pabbrev-debug-display-label-face
+ (overlay-get overlay 'face))
+ (delete-overlay overlay)))
+ (overlays-in (point-min) (point-max))))
(defun pabbrev-debug-show-all-properties()
"Show all existing markers.
@@ -1581,14 +1523,12 @@ This can be rather slow."
Toggling `pabbrev-mode' will tend to turn them on again, as
will `pabbrev-debug-restart-idle-timer'."
(interactive)
- (if pabbrev-short-idle-timer
- (progn
- (cancel-timer pabbrev-short-idle-timer)
- (setq pabbrev-short-idle-timer nil)))
- (if pabbrev-long-idle-timer
- (progn
- (cancel-timer pabbrev-long-idle-timer)
- (setq pabbrev-long-idle-timer nil))))
+ (when pabbrev-short-idle-timer
+ (cancel-timer pabbrev-short-idle-timer)
+ (setq pabbrev-short-idle-timer nil))
+ (when pabbrev-long-idle-timer
+ (cancel-timer pabbrev-long-idle-timer)
+ (setq pabbrev-long-idle-timer nil)))
(defun pabbrev-debug-clear()
(pabbrev-debug-clear-all-hashes)
@@ -1607,21 +1547,18 @@ to the dictionary."
(defun pabbrev-debug-clear-hashes(&optional mode)
"Clear the dictionary for major mode MODE, or the current mode."
(interactive)
- (if (not mode)
- (setq mode major-mode))
+ (unless mode (setq mode major-mode))
(setq pabbrev-prefix-hash-modes
(delq mode pabbrev-prefix-hash-modes))
(setq pabbrev-usage-hash-modes
(delq mode pabbrev-usage-hash-modes))
;; help the GC a bit..
- (if (pabbrev-get-usage-hash)
- (progn
- (clrhash (pabbrev-get-usage-hash))
- (put mode 'pabbrev-usage-hash nil)))
- (if (pabbrev-get-prefix-hash)
- (progn
- (clrhash (pabbrev-get-prefix-hash))
- (put mode 'pabbrev-get-prefix-hash nil))))
+ (when (pabbrev-get-usage-hash)
+ (clrhash (pabbrev-get-usage-hash))
+ (put mode 'pabbrev-usage-hash nil))
+ (when (pabbrev-get-prefix-hash)
+ (clrhash (pabbrev-get-prefix-hash))
+ (put mode 'pabbrev-get-prefix-hash nil)))
(defun pabbrev-debug-clear-all-hashes()
"Clear all hashes for all modes."
- [elpa] externals/pabbrev bc3fc8c090 06/15: Pabbrev-suggestions-delete-window: eq->equal, (continued)
- [elpa] externals/pabbrev bc3fc8c090 06/15: Pabbrev-suggestions-delete-window: eq->equal, Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev 676eecc85a 07/15: Change maintainer and bump minor version., Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev d82c23a563 01/15: Warnings, formatting, inline one-liners, refactoring., Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev 1d3cb0bc7e 08/15: Inline more and add page breaks., Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev 211a06ea01 05/15: Remove XEmacs support., Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev 6242c553aa 09/15: Fix maintainer name, Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev ba7e7824af 10/15: Fix pabbrev-start-idle-timer use before declare, Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev 771ffe3ff7 12/15: Fix close suggestion window debug leftover., Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev 26a4457ade 13/15: Remove minimal-suggestion-length, Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev 7869017d62 15/15: Merge branch 'master' of github.com:phillord/pabbrev into externals/pabbrev, Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev ea437a2210 02/15: Refactored, if->when, inline,
Phillip Lord <=
- [elpa] externals/pabbrev cd0b91a432 04/15: Add dependency on Emacs 25 and package URL., Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev 7b87655c46 11/15: Some more refactoring:, Phillip Lord, 2024/02/06
- [elpa] externals/pabbrev aa1cb9d8f5 14/15: More refactoring., Phillip Lord, 2024/02/06