diff options
author | João Távora <joaotavora@gmail.com> | 2017-10-19 12:33:20 +0100 |
---|---|---|
committer | João Távora <joaotavora@gmail.com> | 2017-10-19 12:33:20 +0100 |
commit | 46366c45cb1cef5c0cc88bb9a868df88f4ed5c1a (patch) | |
tree | af06ca158134feddd71f5fa524d4b00e4558ee58 /doc/misc | |
parent | 4d578d432d4cf1e6826f3c07d119017940dd8e6e (diff) | |
download | emacs-scratch/flymake-augment-api.tar.gz |
Augment Flymake API for third-party extensionsscratch/flymake-augment-api
See
https://lists.gnu.org/archive/html/emacs-devel/2017-10/msg00619.html
* doc/misc/flymake.texi (Flymake error types): Rewrite
example.
(Flymake utility functions): Augment with new API.
* lisp/progmodes/flymake.el (flymake-diagnostics): New function.
(flymake--diag-accessor): New helper macro.
(flymake-diagnostic-buffer, flymake-diagnostic-text)
(flymake-diagnostic-beg, flymake-diagnostic-end)
(flymake-diagnostic-backend): Accessors for diagnostic objects.
(flymake--overlays): Use flymake-diagnostic property.
(flymake--highlight-line): Simplify. Only set
flymake-diagnostic property.
(flymake--handle-report, flymake-goto-next-error): Use
flymake-diagnostic property.
(flymake-show-diagnostic): Use diagnostic object.
(flymake--diagnostics-buffer-entries): Use
flymake-diagnostics.
Diffstat (limited to 'doc/misc')
-rw-r--r-- | doc/misc/flymake.texi | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi index 99ab1271ac9..6e0928f0ee2 100644 --- a/doc/misc/flymake.texi +++ b/doc/misc/flymake.texi @@ -361,34 +361,38 @@ priority but without an overlay face. (flymake-category . flymake-note)))) @end example -@vindex flymake-text +@vindex flymake-diagnostics +@vindex flymake-diagnostic-backend +@vindex flymake-diagnostic-buffer +@vindex flymake-diagnostic-text +@vindex flymake-diagnostic-beg +@vindex flymake-diagnostic-end As you might have guessed, Flymake's annotations are implemented as overlays (@pxref{Overlays,,, elisp, The Emacs Lisp Reference Manual}). Along with the properties that you specify for the specific type of -diagnostic, Flymake adds the property @code{flymake-text} to these -overlays, and sets it to the message string that the backend used to -describe the diagnostic. +diagnostic, Flymake adds the property @code{flymake-diagnostic} to +these overlays, and sets it to the object that the backend created +with @code{flymake-make-diagnostic}. -Since overlays also support arbitrary keymaps, you can use this -property @code{flymake-text} to create interactive annotations, such -as in the following example of binding a @kbd{mouse-3} event (middle -mouse button click) to an Internet search for the text of a -@code{:warning} or @code{:error}. +Since overlays also support arbitrary keymaps, you can this along with +the functions @code{flymake-diagnostics} and +@code{flymake-diagnostic-text} (@pxref{Flymake utility functions}) to +create interactive annotations, such as in the following example of +binding a @kbd{mouse-3} event (middle mouse button click) to an +Internet search for the text of a @code{:warning} or @code{:error}. @example (defun my-search-for-message (event) (interactive "e") - (let ((ovs (overlays-at (posn-point (event-start event)))) - ov) - ;; loop until flymake overlay we clicked on is recovered - (while (not (overlay-get (setq ov (pop ovs)) 'flymake-text))) - (when ov - (eww-browse-url - (concat "https://duckduckgo.com/?q=" - (replace-regexp-in-string " " - "+" - (overlay-get ov 'flymake-text))) - t)))) + (let* ((diags (flymake-diagnostics (posn-point (event-start event)))) + (topmost-diag (car diags))) + (eww-browse-url + (concat + "https://duckduckgo.com/?q=" + (replace-regexp-in-string " " + "+" + (flymake-diagnostic-text topmost-diag))) + t))) (dolist (type '(:warning :error)) (let ((a (assoc type flymake-diagnostic-types-alist))) @@ -513,6 +517,23 @@ Make a Flymake diagnostic for @var{buffer}'s region from @var{beg} to of the problem detected in this region. @end deffn +@cindex access diagnostic object +These objects' properties can be accessed with the functions +@code{flymake-diagnostic-backend}, @code{flymake-diagnostic-buffer}, +@code{flymake-diagnostic-text}, @code{flymake-diagnostic-beg}, +@code{flymake-diagnostic-end} and @code{flymake-diagnostic-type}. + +Additionally, the function @code{flymake-diagnostics} will collect +such objects in the region you specify. + +@cindex collect diagnostic objects +@deffn Function flymake-diagnostics beg end +Get a list of Flymake diagnostics in the region comprised between +@var{beg} and @var{end}. If neither @var{beg} or @var{end} is +supplied, use the whole buffer, otherwise if @var{beg} is non-nil and +@var{end} is nil, consider only diagnostics at @var{beg}. +@end deffn + @cindex buffer position from line and column number It is often the case with external syntax tools that a diagnostic's position is reported in terms of a line number, and sometimes a column |