From c9048dc0e3a1f56f233a4f1d18933e3b853b2071 Mon Sep 17 00:00:00 2001 From: Eivind Fonn Date: Wed, 8 Jun 2016 11:28:36 +0200 Subject: [PATCH] Implement generalized next-error API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function spacemacs//gne-next can be used as next-error-function in any buffer where lines represent “entries” that can be visited. --- layers/+distributions/spacemacs-base/funcs.el | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/layers/+distributions/spacemacs-base/funcs.el b/layers/+distributions/spacemacs-base/funcs.el index 855d10453..48530b7b7 100644 --- a/layers/+distributions/spacemacs-base/funcs.el +++ b/layers/+distributions/spacemacs-base/funcs.el @@ -995,8 +995,7 @@ is nonempty." Delegates to flycheck if it is enabled and the next-error buffer is not visible. Otherwise delegates to regular Emacs next-error." (if (and (bound-and-true-p flycheck-mode) - (let ((buf (or next-error-last-buffer - (next-error-find-buffer)))) + (let ((buf (next-error-find-buffer))) (not (and buf (get-buffer-window buf))))) 'flycheck 'emacs)) @@ -1016,3 +1015,31 @@ is not visible. Otherwise delegates to regular Emacs next-error." (cond ((eq 'flycheck sys) (call-interactively 'flycheck-previous-error)) ((eq 'emacs sys) (call-interactively 'previous-error))))) + +(defvar-local spacemacs--gne-min-line nil + "The first line in the buffer that is a valid result.") +(defvar-local spacemacs--gne-max-line nil + "The last line in the buffer that is a valid result.") +(defvar-local spacemacs--gne-cur-line 0 + "The current line in the buffer. (It is problematic to use +point for this.)") +(defvar-local spacemacs--gne-line-func nil + "The function to call to visit the result on a line.") + +(defun spacemacs//gne-next (num reset) + "A generalized next-error function. This function can be used +as `next-error-function' in any buffer that conforms to the +Spacemacs generalized next-error API. + +The variables `spacemacs--gne-min-line', +`spacemacs--gne-max-line', and `spacemacs--line-func' must be +set." + (when reset (setq spacemacs--gne-cur-line + spacemacs--gne-min-line)) + (setq spacemacs--gne-cur-line + (min spacemacs--gne-max-line + (max spacemacs--gne-min-line + (+ num spacemacs--gne-cur-line)))) + (goto-line spacemacs--gne-cur-line) + (funcall spacemacs--gne-line-func + (buffer-substring (point-at-bol) (point-at-eol))))