Simplify label management functions
By calling `dispass-label' with it's brand spankin' new `--add' and `--remove' switches the `dispass-add-label' and `dispass-remove-label' functions can be greatly simplified. This also removes the need for the `dispass-file', which assumed the file was in `~/', though that is not the default case with DisPass anymore.
This commit is contained in:
parent
09e65e6a35
commit
0a8d1b6163
1 changed files with 26 additions and 29 deletions
55
dispass.el
55
dispass.el
|
@ -53,12 +53,6 @@
|
||||||
:type 'string
|
:type 'string
|
||||||
:risky t)
|
:risky t)
|
||||||
|
|
||||||
(defcustom dispass-file "~/.dispass"
|
|
||||||
"The location of your dispass file."
|
|
||||||
:package-version '(dispass . "1")
|
|
||||||
:group 'dispass
|
|
||||||
:type '(file))
|
|
||||||
|
|
||||||
(defvar dispass-labels-mode-map
|
(defvar dispass-labels-mode-map
|
||||||
(let ((map (make-sparse-keymap)))
|
(let ((map (make-sparse-keymap)))
|
||||||
(set-keymap-parent map tabulated-list-mode-map)
|
(set-keymap-parent map tabulated-list-mode-map)
|
||||||
|
@ -86,6 +80,11 @@
|
||||||
(buffer-disable-undo buffer)
|
(buffer-disable-undo buffer)
|
||||||
(kill-buffer buffer)))
|
(kill-buffer buffer)))
|
||||||
|
|
||||||
|
(defun dispass-label-at-point ()
|
||||||
|
"When in `dispass-labels-mode', get the label at `point'."
|
||||||
|
(let ((labels-mode-p (eq major-mode 'dispass-labels-mode)))
|
||||||
|
(tabulated-list-get-id)))
|
||||||
|
|
||||||
(defun dispass-process-filter-for (label)
|
(defun dispass-process-filter-for (label)
|
||||||
"Create a function that will process any lines whilst keeping
|
"Create a function that will process any lines whilst keeping
|
||||||
an eye out for LABEL."
|
an eye out for LABEL."
|
||||||
|
@ -172,34 +171,32 @@ an eye out for LABEL."
|
||||||
;; Labels management
|
;; Labels management
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun dispass-add-label (label length hashtype)
|
(defun dispass-add-label (label length hashtype)
|
||||||
"Add LABEL with length LENGTH and hashtype HASHTYPE to `dispass-file'."
|
"Add LABEL with length LENGTH and hashtype HASHTYPE to DisPass."
|
||||||
(interactive "MLabel: \nnLength: \nMHash: ")
|
(interactive
|
||||||
(with-temp-buffer
|
(list (read-from-minibuffer "Label: ")
|
||||||
(insert (format "%s length=%d hash=%s\n" label length hashtype))
|
(read-from-minibuffer
|
||||||
(append-to-file (point-min) (point-max) dispass-file))
|
(format "Length (%d): " dispass-default-length) nil nil t nil
|
||||||
(when (eq major-mode 'dispass-labels-mode)
|
(number-to-string dispass-default-length))
|
||||||
(revert-buffer)))
|
(symbol-name (read-from-minibuffer
|
||||||
|
"Algorithm (dispass1): " nil nil t nil "dispass1"))))
|
||||||
|
(shell-command
|
||||||
|
(format "%s --add %s:%d:%s" dispass-labels-executable label length
|
||||||
|
hashtype)))
|
||||||
|
|
||||||
(defun dispass-remove-label (&optional label)
|
;;;###autoload
|
||||||
"Remove LABEL from `dispass-file', if LABEL is not given
|
(defun dispass-remove-label (label)
|
||||||
|
"Remove LABEL from DisPass, if LABEL is not given
|
||||||
`tabulated-list-get-id' will be used to get the currently
|
`tabulated-list-get-id' will be used to get the currently
|
||||||
pointed-at label. If neither LABEL is not found an error is
|
pointed-at label. If neither LABEL is not found an error is
|
||||||
thrown."
|
thrown."
|
||||||
(interactive)
|
(interactive
|
||||||
(let* ((labels-mode-p (eq major-mode 'dispass-labels-mode))
|
(list (or (dispass-label-at-point)
|
||||||
(label (or label (when labels-mode-p (tabulated-list-get-id)))))
|
(completing-read
|
||||||
(unless label
|
"Label: " (mapcar (lambda (elm) (elt elm 0))
|
||||||
(error
|
(dispass-get-labels))))))
|
||||||
"LABEL required or must be called from `dispass-labels-mode'."))
|
|
||||||
|
|
||||||
(with-temp-buffer
|
(shell-command
|
||||||
(insert-file-contents dispass-file)
|
(format "%s --remove %s" dispass-labels-executable label)))
|
||||||
(when (re-search-forward (concat "^" label) nil t)
|
|
||||||
(kill-whole-line)
|
|
||||||
(write-file dispass-file)))
|
|
||||||
|
|
||||||
(when labels-mode-p
|
|
||||||
(revert-buffer))))
|
|
||||||
|
|
||||||
(defun dispass-from-button (button)
|
(defun dispass-from-button (button)
|
||||||
"Call dispass with information from BUTTON."
|
"Call dispass with information from BUTTON."
|
||||||
|
|
Loading…
Reference in a new issue