[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 13c02a6 06/13: Added dictionary printing
From: |
Ian Dunn |
Subject: |
[elpa] master 13c02a6 06/13: Added dictionary printing |
Date: |
Sun, 4 Feb 2018 12:32:33 -0500 (EST) |
branch: master
commit 13c02a66c09c87f8304f31e92e1abd5b33a5afe9
Author: Ian Dunn <address@hidden>
Commit: Ian Dunn <address@hidden>
Added dictionary printing
* paced.el (paced-tabulated-list-dictionary): New local variable.
(paced-dictionary-length-of-longest-word):
(paced-dictionary-tabulated-list-entries):
(paced-tabulated-list-revert): Helper functions for dictionary printing.
(paced-dictionary-print): New defun to print a dictionary's contents.
(paced-print-current-dictionary): Print the current dictionary.
(paced-print-named-dictionary): Print a named dictionary.
---
paced.el | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/paced.el b/paced.el
index 6309cdb..3f40176 100644
--- a/paced.el
+++ b/paced.el
@@ -1065,6 +1065,63 @@ must be set with `paced-edit-named-dictionary' or
+;;; Print a Dictionary in a Dedicated Buffer
+
+(defvar-local paced-tabulated-list-dictionary nil
+ "Dictionary printed in a tabulated list buffer.")
+
+(cl-defmethod paced-dictionary-length-of-longest-word ((dict paced-dictionary))
+ "Return the length of the longest word in DICT."
+ (seq-max
+ (map-apply
+ (lambda (key _value)
+ (length key))
+ (oref dict usage-hash))))
+
+(cl-defmethod paced-dictionary-tabulated-list-entries ((dict paced-dictionary))
+ "Create a value for `tabulated-list-entries' from DICT."
+ (map-apply
+ (lambda (key value)
+ (list key (vector key (number-to-string value))))
+ (oref dict usage-hash)))
+
+(defun paced-tabulated-list-revert ()
+ "Revert a `tabulated-list-mode' buffer from its dictionary."
+ (let* ((dict paced-tabulated-list-dictionary)
+ (longest-length (paced-dictionary-length-of-longest-word dict)))
+ (setq tabulated-list-format
+ (vector `("Word" ,longest-length t . (:right-align t))
+ `("Count" 10 t)))
+ (setq tabulated-list-entries (paced-dictionary-tabulated-list-entries
dict))))
+
+(cl-defmethod paced-dictionary-print ((dict paced-dictionary))
+ "Print the contents of DICT in a dedicated buffer."
+ (let* ((buffer-name (format "*Paced Dictionary - %s*" (paced-dictionary-name
dict)))
+ (buffer (get-buffer-create buffer-name)))
+ (with-current-buffer buffer
+ (tabulated-list-mode)
+ (setq paced-tabulated-list-dictionary dict)
+ (paced-tabulated-list-revert)
+ (tabulated-list-init-header)
+ (tabulated-list-print))
+ (display-buffer buffer)))
+
+(defun paced-print-current-dictionary ()
+ "Print the contents of the current dictionary in a dedicated buffer."
+ (interactive)
+ (if-let* ((dict (paced-current-dictionary)))
+ (paced-dictionary-print dict)
+ (user-error "No dictionary found for current buffer")))
+
+(defun paced-print-named-dictionary (name)
+ "Print the contents of the dictionary with name NAME."
+ (interactive (list (paced-read-dictionary)))
+ (if-let* ((dict (paced-named-dictionary name)))
+ (paced-dictionary-print dict)
+ (error "No paced dictionary called '%s' has been registered" name)))
+
+
+
(declare-function lm-report-bug "lisp-mnt" (topic))
(defun paced-submit-bug-report (topic)
- [elpa] master updated (edbdf4e -> a9eb761), Ian Dunn, 2018/02/04
- [elpa] master 01069d1 02/13: Fixed failing effort test, Ian Dunn, 2018/02/04
- [elpa] master c7fc9a4 01/13: Updated copyright, Ian Dunn, 2018/02/04
- [elpa] master 13c02a6 06/13: Added dictionary printing,
Ian Dunn <=
- [elpa] master a9d3d12 07/13: Added support for choosing which side of thing-at-point to consider for exclusion, Ian Dunn, 2018/02/04
- [elpa] master 56eeaff 04/13: Fixed up Changelog in documentation, Ian Dunn, 2018/02/04
- [elpa] master b73fff8 09/13: Added paced-repopulate-current-dictionary-async, Ian Dunn, 2018/02/04
- [elpa] master 1171a76 08/13: Added support for excluding words past a certain character limit, Ian Dunn, 2018/02/04
- [elpa] master bc5d7cd 10/13: Silenced byte-compiler, Ian Dunn, 2018/02/04
- [elpa] master d57675f 03/13: Added new forms for set-property! and fixed up build system, Ian Dunn, 2018/02/04
- [elpa] master 35acd8c 05/13: Cleaned up Changelog some more, Ian Dunn, 2018/02/04
- [elpa] master a9eb761 13/13: Merge commit '35acd8c2f9710e54ec3f433ae4af40cfff635295', Ian Dunn, 2018/02/04
- [elpa] master 463d752 11/13: Cleaned up code and added documentation of new features, Ian Dunn, 2018/02/04
- [elpa] master f4d03a3 12/13: Merge commit '463d752d4703af93ea86df8f07b244e8fc851617', Ian Dunn, 2018/02/04