leoliu pushed a commit to branch master in repository elpa. commit b42bf956931c1625b9acd54050549877409484aa Author: Leo Liu <sdl....@gmail.com> Date: Sun Jun 15 12:17:04 2014 +0800
Fix #58: Search history can be manipulated with C-k and C-y --- README.rst | 1 + ggtags.el | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 0 deletions(-) diff --git a/README.rst b/README.rst index 8e1d352..671b27e 100644 --- a/README.rst +++ b/README.rst @@ -306,6 +306,7 @@ NEWS ``ggtags-view-search-history``. #. The output buffer from ``ggtags-view-search-history`` looks cleaner. +#. Search history items can be re-arranged with ``C-k`` and ``C-y``. [2014-05-06 Tue] 0.8.4 ++++++++++++++++++++++ diff --git a/ggtags.el b/ggtags.el index c3c80a5..dbc9a81 100644 --- a/ggtags.el +++ b/ggtags.el @@ -1073,6 +1073,9 @@ Global and Emacs." (define-key m "\M-p" 'ggtags-view-search-history-prev) (define-key m "n" 'ggtags-view-search-history-next) (define-key m "\M-n" 'ggtags-view-search-history-next) + (define-key m "\C-k" 'ggtags-view-search-history-kill) + (define-key m [remap yank] (lambda (&optional arg) (interactive "P") (yank arg))) + (define-key m "\C-c\C-c" 'ggtags-view-search-history-update) (define-key m "r" 'ggtags-save-to-register) (define-key m "\r" 'ggtags-view-search-history-action) (define-key m "q" 'kill-buffer-and-window) @@ -1093,6 +1096,41 @@ Global and Emacs." (interactive "p") (ggtags-view-search-history-next (- (or arg 1)))) +(defun ggtags-view-search-history-kill (&optional append) + (interactive "P") + (let* ((node (or (ewoc-locate ggtags-global-search-ewoc) + (user-error "No node at point"))) + (next (ewoc-next ggtags-global-search-ewoc node)) + (text (filter-buffer-substring (ewoc-location node) + (if next (ewoc-location next) + (point-max))))) + (put-text-property + 0 (length text) 'yank-handler + (list (lambda (arg) + (if (not ggtags-global-search-ewoc) + (insert (car arg)) + (let* ((inhibit-read-only t) + (node (unless (looking-at-p "[ \t\n]*\\'") + (ewoc-locate ggtags-global-search-ewoc)))) + (if node + (ewoc-enter-before ggtags-global-search-ewoc + node (cadr arg)) + (ewoc-enter-last ggtags-global-search-ewoc (cadr arg)))))) + (list text (ewoc-data node))) + text) + (if append (kill-append text nil) + (kill-new text)) + (let ((inhibit-read-only t)) + (ewoc-delete ggtags-global-search-ewoc node)))) + +(defun ggtags-view-search-history-update (&optional noconfirm) + "Update `ggtags-global-search-history' to current buffer." + (interactive "P") + (when (or noconfirm + (yes-or-no-p "Modify `ggtags-global-search-history'?")) + (setq ggtags-global-search-history + (ewoc-collect ggtags-global-search-ewoc #'identity)))) + (defun ggtags-view-search-history-action () (interactive) (let ((data (ewoc-data (or (ewoc-locate ggtags-global-search-ewoc)