From: Elijah G <eg642616@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: sbaugh@catern.com, sbaugh@janestreet.com, philipk@posteo.net,
emacs-devel@gnu.org, luangruo@yahoo.com
Subject: Re: [PATCH] Flymake Support Indicator Errors in Margin
Date: Sat, 6 Apr 2024 14:14:34 -0600 [thread overview]
Message-ID: <CACnP4NKfA6LLzS5wEk0thS0+w6YLgEMvgesScT7z9OsJSgtXeg@mail.gmail.com> (raw)
In-Reply-To: <86edbi3eqw.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 3249 bytes --]
On Sat, Apr 6, 2024 at 5:35 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Elijah G <eg642616@gmail.com>
> > Date: Wed, 27 Mar 2024 15:29:28 -0600
> > Cc: Eli Zaretskii <eliz@gnu.org>, Spencer Baugh <sbaugh@janestreet.com>, philipk@posteo.net,
> > emacs-devel@gnu.org, Po Lu <luangruo@yahoo.com>
> >
> > I've now updated the patch to allow auto resize margins and using margins
> > when it's in terminal frames.
>
> Thanks, I think this is almost ready to be installed; see a few minor
> comments below.
>
> > Sadly I couldn't find anything for detecting HDiPI frames, so the user
> > must have to configure it.
>
> I don't think Emacs should second-guess the user in this matter: let
> the user decide whether the fringes are too narrow for these
> indicators.
>
> > +(defcustom flymake-indicator-type (if (display-graphic-p)
> > + 'fringes
> > + 'margins)
> > + "Indicate which indicator type to use for display errors.
> > +
> > +The value can be nil (dont indicate errors but just highlight them),
> ^^^^
> "don't"
>
> > +(defcustom flymake-margin-indicators-string
> > + '((error "!!" compilation-error)
> > + (warning "!" compilation-warning)
> > + (note "!" compilation-info))
> > + "Strings used for margins indicators.
> > +The value of each list may be a list of 3 elements where specifies the
> > +error type, its string to use and its face,
> ^^^^^^^^^^
> "the string"
>
> > +or a list of 2 elements specifying only the error type and its string.
> ^^^^^^^^^^^^^^
> "and the corresponding string"
>
> > +Indicators can be an ASCII or non-ASCII string.
>
> This sentence is redundant, so I suggest to remove it. The ASCII vs
> non-ASCII issue is only relevant for the default value; users can do
> whatever they want when they customize the option.
>
> > +(defcustom flymake-autoresize-margins t
> > + "If non-nil automatically resize margin-width.
> ^
> Comma is missing there. Also, how about telling what triggers
> the resizing?
>
> > +Only if `flymake-indicator-type' is set to margins."
> ^^^^^^^
> "Only relevant if..."
>
> > +(defvar-local flymake-original-margin-width nil
> > + "Store original margin width")
>
> Should this be an internal variable (named flymake--original-margin-width)?
> Also, please consider telling in the doc string when is the width restored.
>
> > +(defun flymake--resize-margins (&optional og-width)
> > + "Resize current window margins according `flymake-margin-indicator-position'.
> ^^^^^^^^^
> "according to"
>
> > +Return to original margin width if OG-WIDTH is non-nil."
>
> Suggest to rename OG-WIDTH to ORIG-WIDTH.
>
> Last, but not least: please mention this change (and the new user
> options) in NEWS and in the Flymake manual.
Thank you, I've now fixed the patch and documented the changes done.
Also I have a question, Do I need to assign copyright each time
that I want to contribute to Flymake?
I have a lot of ideas that I would like to contribute.
[-- Attachment #2: 0001-Flymake-support-for-indicating-errors-in-margin.patch --]
[-- Type: application/octet-stream, Size: 13013 bytes --]
From 4ed73c51e7d82b6ade8ecb519066ba7e006beaf4 Mon Sep 17 00:00:00 2001
From: "Elias G. B. Perez" <eg642616@gmail.com>
Date: Sat, 6 Apr 2024 13:57:30 -0600
Subject: [PATCH] Flymake support for indicating errors in margin
Add optional support for display flymake error in margin,
this allow displaying error indicators in both graphical and
terminal frames.
* doc/misc/flymake.texi (Customizable variables)
(Flymake error types): Document new margin indicator.
* etc/NEWS: Announce the new Flymake user option for margin
indicators.
* lisp/progmodes/flymake.el (flymake-indicator-type)
(flymake-margin-indicators-string, flymake-autoresize-margins)
(flymake-margin-indicator-position): New user options.
(flymake--original-margin-width): Add buffer-local variable for
store original buffer margin width.
(flymake-error, flymake-warning, flymake-note): Use new margin
value.
(flymake--indicator-overlay-spec): Rework and Rename from
flymake--fringe-overlay-spec.
(flymake--resize-margins): Add new function for resize margin
width.
(flymake--highlight-line, flymake-mode): Rework.
---
doc/misc/flymake.texi | 25 +++++++
etc/NEWS | 21 ++++++
lisp/progmodes/flymake.el | 134 +++++++++++++++++++++++++++++++++-----
3 files changed, 165 insertions(+), 15 deletions(-)
diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi
index 84a74a9..7b42de0 100644
--- a/doc/misc/flymake.texi
+++ b/doc/misc/flymake.texi
@@ -309,6 +309,11 @@ Customizable variables
A custom face for highlighting regions for which a note has been
reported.
+@item flymake-indicator-type
+Which indicator type should Flymake use.
+Depending on your preference, this can either use @code{fringes} or
+@code{margins} for indicating errors.
+
@item flymake-error-bitmap
A bitmap used in the fringe to mark lines for which an error has
been reported.
@@ -320,6 +325,18 @@ Customizable variables
@item flymake-fringe-indicator-position
Which fringe (if any) should show the warning/error bitmaps.
+@item flymake-margin-indicators-string
+A List used for specify string, face and error types to
+use in the margin indicators.
+
+@item flymake-margin-indicator-position
+Which margin (if any) should show the warning/error strings.
+
+@item flymake-autoresize-margins
+If non-@code{nil}, will resize margins either @code{flymake-mode} is
+non-@code{nil} or @code{nil}.
+Only relevant if @code{flymake-indicator-type} is set to @code{margins}.
+
@item flymake-wrap-around
If non-@code{nil}, moving to errors with @code{flymake-goto-next-error} and
@code{flymake-goto-prev-error} wraps around buffer boundaries.
@@ -387,6 +404,14 @@ Flymake error types
variables}). It is overridden by any @code{before-string} overlay
property.
+@item
+@cindex margin of diagnostic
+@code{flymake-margin-string}, an string displayed in the margin
+according to @code{flymake-margin-indicator-position}.
+The value actually follows the syntax of @code{flymake-margin-indicators-string}
+(@pxref{Customizable variables}). It is overridden by any
+@code{before-string} overlay property.
+
@item
@code{flymake-overlay-control}, an alist ((@var{OVPROP} . @var{VALUE})
@var{...}) of further properties used to affect the appearance of
diff --git a/etc/NEWS b/etc/NEWS
index 375c27a..8a7ecfb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1201,6 +1201,27 @@ in a clean environment.
** Flymake
++++
+*** New user option 'flymake-indicator-type'.
+This user option controls which error indicator type Flymake should use
+in current buffer. Depending on your preference, this can either use
+fringes or margins for indicating errors.
+
++++
+*** New user option 'flymake-margin-indicators-string'
+It controls the string, their face and type error to display in
+margin indicators.
+
++++
+*** New user option 'flymake-autoresize-margins'
+When non-nil, Flymake will resize margins either `flymake-mode` is
+non-nil or nil.
+Only relevant if `flymake-indicator-type` is set to `margins`.
+
++++
+*** New user option 'flymake-margin-indicator-position'
+It controls which position should Flymake show margin indicators.
+
+++
*** New user option 'flymake-show-diagnostics-at-end-of-line'.
When non-nil, Flymake shows summarized descriptions of diagnostics at
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 779c612..fc64368 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -180,6 +180,59 @@ flymake-fringe-indicator-position
(const right-fringe)
(const :tag "No fringe indicators" nil)))
+(defcustom flymake-indicator-type (if (display-graphic-p)
+ 'fringes
+ 'margins)
+ "Indicate which indicator type to use for display errors.
+
+The value can be nil (don't indicate errors but just highlight them),
+fringes (use fringes) or margins (use margins)
+
+Difference between fringes and margin is that fringes support diplaying
+bitmaps on graphical displays and margins display text in a blank area
+from current buffer that works in both graphical and text displays.
+
+See Info node `Fringes' and Info node `(elisp)Display Margins'."
+ :version "30.1"
+ :type '(choice (const :tag "Use Fringes" fringes)
+ (const :tag "Use Margins "margins)
+ (const :tag "No indicators" nil)))
+
+(defcustom flymake-margin-indicators-string
+ '((error "!!" compilation-error)
+ (warning "!" compilation-warning)
+ (note "!" compilation-info))
+ "Strings used for margins indicators.
+The value of each list may be a list of 3 elements where specifies the
+error type, the string to use and its face,
+or a list of 2 elements specifying only the error type and
+the corresponding string.
+
+The option `flymake-margin-indicator-position' controls how and where
+this is used."
+ :version "30.1"
+ :type '(repeat :tag "Error types lists"
+ (list :tag "String and face for error types"
+ (symbol :tag "Error type")
+ (string :tag "String")
+ (face :tag "Face"))))
+
+(defcustom flymake-autoresize-margins t
+ "If non-nil, automatically resize margin-width calling flymake--resize-margins.
+
+Only relevant if `flymake-indicator-type' is set to margins."
+ :version "30.1"
+ :type 'boolean)
+
+(defcustom flymake-margin-indicator-position 'left-margin
+ "The position to put Flymake margin indicator.
+The value can be nil (do not use indicators), `left-margin' or `right-margin'.
+See `flymake-margin-indicators-string'."
+ :version "30.1"
+ :type '(choice (const left-margin)
+ (const right-margin)
+ (const :tag "No margin indicators" nil)))
+
(make-obsolete-variable 'flymake-start-syntax-check-on-newline
"can check on newline in post-self-insert-hook"
"27.1")
@@ -258,6 +311,11 @@ flymake-timer
(defvar-local flymake-check-start-time nil
"Time at which syntax check was started.")
+(defvar-local flymake--original-margin-width nil
+ "Store original margin width.
+Used by `flymake--resize-margins' for restore original margin width
+when flymake is turned off.")
+
(defun flymake--log-1 (level sublog msg &rest args)
"Do actual work for `flymake-log'."
(let (;; never popup the log buffer
@@ -630,6 +688,7 @@ flymake-diagnostic-types-alist
(put 'flymake-error 'face 'flymake-error)
(put 'flymake-error 'flymake-bitmap 'flymake-error-bitmap)
+(put 'flymake-error 'flymake-margin-string (alist-get 'error flymake-margin-indicators-string))
(put 'flymake-error 'severity (warning-numeric-level :error))
(put 'flymake-error 'mode-line-face 'flymake-error-echo)
(put 'flymake-error 'echo-face 'flymake-error-echo)
@@ -638,6 +697,7 @@ flymake-diagnostic-types-alist
(put 'flymake-warning 'face 'flymake-warning)
(put 'flymake-warning 'flymake-bitmap 'flymake-warning-bitmap)
+(put 'flymake-warning 'flymake-margin-string (alist-get 'warning flymake-margin-indicators-string))
(put 'flymake-warning 'severity (warning-numeric-level :warning))
(put 'flymake-warning 'mode-line-face 'flymake-warning-echo)
(put 'flymake-warning 'echo-face 'flymake-warning-echo)
@@ -646,6 +706,7 @@ flymake-diagnostic-types-alist
(put 'flymake-note 'face 'flymake-note)
(put 'flymake-note 'flymake-bitmap 'flymake-note-bitmap)
+(put 'flymake-note 'flymake-margin-string (alist-get 'note flymake-margin-indicators-string))
(put 'flymake-note 'severity (warning-numeric-level :debug))
(put 'flymake-note 'mode-line-face 'flymake-note-echo)
(put 'flymake-note 'echo-face 'flymake-note-echo)
@@ -682,19 +743,53 @@ flymake--severity
(flymake--lookup-type-property type 'severity
(warning-numeric-level :error)))
-(defun flymake--fringe-overlay-spec (bitmap &optional recursed)
- (if (and (symbolp bitmap)
- (boundp bitmap)
- (not recursed))
- (flymake--fringe-overlay-spec
- (symbol-value bitmap) t)
- (and flymake-fringe-indicator-position
- bitmap
- (propertize "!" 'display
- (cons flymake-fringe-indicator-position
- (if (listp bitmap)
- bitmap
- (list bitmap)))))))
+(defun flymake--indicator-overlay-spec (indicator)
+ "Return INDICATOR as propertized string to use in error indicators."
+ (let* ((value (if (symbolp indicator)
+ (symbol-value indicator)
+ indicator))
+ (indicator-car (if (listp value)
+ (car value)
+ value))
+ (indicator-cdr (if (listp value)
+ (cdr value))))
+ (cond
+ ((symbolp indicator-car)
+ (propertize "!" 'display
+ (cons flymake-fringe-indicator-position
+ (if (listp value)
+ value
+ (list value)))))
+ ((stringp indicator-car)
+ (propertize "!"
+ 'display
+ `((margin ,flymake-margin-indicator-position)
+ ,(propertize
+ indicator-car
+ 'face
+ `(:inherit (,indicator-cdr
+ default)))))))))
+
+(defun flymake--resize-margins (&optional orig-width)
+ "Resize current window margins according to `flymake-margin-indicator-position'.
+Return to original margin width if ORIG-WIDTH is non-nil."
+ (when (and (eq flymake-indicator-type 'margins)
+ flymake-autoresize-margins)
+ (cond
+ ((and orig-width flymake--original-margin-width)
+ (if (eq flymake-margin-indicator-position 'left-margin)
+ (setq-local left-margin-width flymake--original-margin-width)
+ (setq-local right-margin-width flymake--original-margin-width)))
+ (t
+ (if (eq flymake-margin-indicator-position 'left-margin)
+ (setq-local flymake--original-margin-width left-margin-width
+ left-margin-width 2)
+ (setq-local flymake--original-margin-width right-margin-width
+ right-margin-width 2))))
+ ;; Apply margin to all windows avalaibles
+ (mapc (lambda (x)
+ (set-window-buffer x (window-buffer x)))
+ (get-buffer-window-list nil nil 'visible))))
(defun flymake--equal-diagnostic-p (a b)
"Tell if A and B are equivalent `flymake--diag' objects."
@@ -840,10 +935,13 @@ flymake--highlight-line
type prop value)))))
(default-maybe 'face 'flymake-error)
(default-maybe 'before-string
- (flymake--fringe-overlay-spec
+ (flymake--indicator-overlay-spec
(flymake--lookup-type-property
type
- 'flymake-bitmap
+ (cond ((eq flymake-indicator-type 'fringes)
+ 'flymake-bitmap)
+ ((eq flymake-indicator-type 'margins)
+ 'flymake-margin-string))
(alist-get 'bitmap (alist-get type ; backward compat
flymake-diagnostic-types-alist)))))
;; (default-maybe 'after-string
@@ -1285,6 +1383,9 @@ flymake-mode
(add-hook 'kill-buffer-hook 'flymake-kill-buffer-hook nil t)
(add-hook 'eldoc-documentation-functions 'flymake-eldoc-function t t)
+ ;; AutoResize margins.
+ (flymake--resize-margins)
+
;; If Flymake happened to be already ON, we must cleanup
;; existing diagnostic overlays, lest we forget them by blindly
;; reinitializing `flymake--state' in the next line.
@@ -1333,6 +1434,9 @@ flymake-mode
;;+(remove-hook 'find-file-hook (function flymake-find-file-hook) t)
(remove-hook 'eldoc-documentation-functions 'flymake-eldoc-function t)
+ ;; return margin to original size
+ (flymake--resize-margins t)
+
(when flymake-timer
(cancel-timer flymake-timer)
(setq flymake-timer nil))
--
2.44.0.windows.1
next prev parent reply other threads:[~2024-04-06 20:14 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-11 23:18 [PATCH] Flymake Support Indicator Errors in Margin Elijah G
2024-03-12 9:24 ` Philip Kaludercic
2024-03-12 17:22 ` Elijah G
2024-03-13 12:18 ` Eli Zaretskii
2024-03-14 1:50 ` Elijah G
2024-03-14 11:05 ` Eli Zaretskii
2024-03-14 11:28 ` João Távora
2024-03-14 15:35 ` Elijah G
2024-03-16 11:10 ` Eli Zaretskii
2024-03-17 16:44 ` bird
2024-03-17 17:01 ` Eli Zaretskii
2024-03-17 17:34 ` Elijah G
2024-03-17 18:43 ` bird
2024-03-17 19:21 ` Elijah G
2024-03-25 1:46 ` Elijah G
2024-03-27 0:13 ` sbaugh
2024-03-27 0:36 ` Elijah G
2024-03-27 21:29 ` Elijah G
2024-03-28 6:01 ` Eli Zaretskii
2024-03-28 17:34 ` Elijah G
2024-04-06 11:36 ` Eli Zaretskii
2024-03-28 7:30 ` Juri Linkov
2024-03-28 17:44 ` Elijah G
2024-04-06 11:35 ` Eli Zaretskii
2024-04-06 20:14 ` Elijah G [this message]
2024-04-07 5:47 ` Eli Zaretskii
2024-04-07 17:20 ` Elijah G
2024-04-18 9:10 ` Eli Zaretskii
2024-03-19 7:03 ` Augusto Stoffel
2024-03-17 17:49 ` Elijah G
2024-03-19 7:04 ` Augusto Stoffel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACnP4NKfA6LLzS5wEk0thS0+w6YLgEMvgesScT7z9OsJSgtXeg@mail.gmail.com \
--to=eg642616@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=luangruo@yahoo.com \
--cc=philipk@posteo.net \
--cc=sbaugh@catern.com \
--cc=sbaugh@janestreet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).