From 0a8d1b6163b415c5ef559234cd65632759748bb9 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Tue, 8 Jan 2013 00:35:57 +0100 Subject: 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. --- dispass.el | 59 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/dispass.el b/dispass.el index f2f8d8e..36e9eac 100644 --- a/dispass.el +++ b/dispass.el @@ -53,12 +53,6 @@ :type 'string :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 (let ((map (make-sparse-keymap))) (set-keymap-parent map tabulated-list-mode-map) @@ -86,6 +80,11 @@ (buffer-disable-undo 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) "Create a function that will process any lines whilst keeping an eye out for LABEL." @@ -172,34 +171,32 @@ an eye out for LABEL." ;; Labels management ;;;###autoload (defun dispass-add-label (label length hashtype) - "Add LABEL with length LENGTH and hashtype HASHTYPE to `dispass-file'." - (interactive "MLabel: \nnLength: \nMHash: ") - (with-temp-buffer - (insert (format "%s length=%d hash=%s\n" label length hashtype)) - (append-to-file (point-min) (point-max) dispass-file)) - (when (eq major-mode 'dispass-labels-mode) - (revert-buffer))) - -(defun dispass-remove-label (&optional label) - "Remove LABEL from `dispass-file', if LABEL is not given + "Add LABEL with length LENGTH and hashtype HASHTYPE to DisPass." + (interactive + (list (read-from-minibuffer "Label: ") + (read-from-minibuffer + (format "Length (%d): " dispass-default-length) nil nil t nil + (number-to-string dispass-default-length)) + (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))) + +;;;###autoload +(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 pointed-at label. If neither LABEL is not found an error is thrown." - (interactive) - (let* ((labels-mode-p (eq major-mode 'dispass-labels-mode)) - (label (or label (when labels-mode-p (tabulated-list-get-id))))) - (unless label - (error - "LABEL required or must be called from `dispass-labels-mode'.")) - - (with-temp-buffer - (insert-file-contents dispass-file) - (when (re-search-forward (concat "^" label) nil t) - (kill-whole-line) - (write-file dispass-file))) - - (when labels-mode-p - (revert-buffer)))) + (interactive + (list (or (dispass-label-at-point) + (completing-read + "Label: " (mapcar (lambda (elm) (elt elm 0)) + (dispass-get-labels)))))) + + (shell-command + (format "%s --remove %s" dispass-labels-executable label))) (defun dispass-from-button (button) "Call dispass with information from BUTTON." -- cgit v1.2.3-54-g00ecf