[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-
From: |
Alan Mackenzie |
Subject: |
Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling |
Date: |
Tue, 27 Aug 2019 19:36:52 +0000 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
Hello, Eli and Stefan.
On Sun, Aug 25, 2019 at 22:37:39 +0300, Eli Zaretskii wrote:
> > Date: Sun, 25 Aug 2019 19:06:37 +0000
> > From: Alan Mackenzie <address@hidden>
> > Cc: address@hidden
> > > 2- Why insert a prefix string (an "inserted arrow") instead of using
> > > a "regular overwriting arrow"?
> > Because the overwriting arrow would obliterate the first two characters
> > of the file name. I actually tried this first, and it wasn't
> > satisfactory. This contrasts with another use of the overwriting arrow
> > in edebug, where (usually) only WS gets overwritten, and it is important
> > not to disturb the visible indentation.
> Did you consider to use the display margin instead? You can have an
> overlay display in the margin by putting a 'display' property on the
> overlay string. The advantage of using the margin is that it will
> keep the buffer text aligned.
OK, thanks for telling me about this. I propose installing the following
patch which implements the arrow in the margin (and supplements my
earlier commit) into master. Criticism, as always, will be welcomed.
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 09188dc14b..931f66ef03 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -2602,45 +2602,70 @@ compilation-set-window
(point)))
(set-window-point w mk))))
-(defvar-local overlay-arrow-overlay nil
+(defvar-local compilation-arrow-overlay nil
"Overlay with the before-string property of `overlay-arrow-string'.
When non-nil, this overlay causes redisplay to display `overlay-arrow-string'
at the overlay's start position.")
+(defvar compilation-margin-string "=>"
+ "The string which will appear in the margin in compilation mode.
+This must be two characters long; there should be no need to
+change the default.")
+(put-text-property 0 2 'face 'default compilation-margin-string)
+
+(defvar compilation-dummy-string ">"
+ "A string which is only a placeholder for compilation-margin-string.
+It's actual value is never used, but must be one character long.")
+(put-text-property 0 1 'display
+ `((margin left-margin) ,compilation-margin-string)
+ compilation-dummy-string)
+
+(defun compilation-set-up-arrow-spec-in-margin ()
+ "Set up compilation-arrow-overlay to display as an arrow in a margin."
+ (setq overlay-arrow-string "")
+ (overlay-put compilation-arrow-overlay
+ 'before-string compilation-dummy-string)
+ (set-window-margins (selected-window) 2))
+
+(defun compilation-tear-down-arrow-spec-in-margin ()
+ "Restore compilation-arrow-overlay to not using the margin, which is
removed."
+ (overlay-put compilation-arrow-overlay 'before-string nil)
+ (delete-overlay compilation-arrow-overlay)
+ (setq compilation-arrow-overlay nil)
+ (set-window-margins (selected-window) 0))
+
(defun compilation-set-overlay-arrow (w)
"Set up, or switch off, the overlay-arrow for window W."
- (with-current-buffer (window-buffer w)
- (if (and (eq compilation-context-lines t)
- (equal (car (window-fringes w)) 0)) ; No left fringe
- ;; Insert a "=>" before-string overlay at the beginning of the
- ;; line pointed to by `overlay-arrow-position'.
- (cond
- ((overlayp overlay-arrow-overlay)
- (when (not (eq (overlay-start overlay-arrow-overlay)
- overlay-arrow-position))
- (if overlay-arrow-position
- (progn
- (move-overlay overlay-arrow-overlay
- overlay-arrow-position overlay-arrow-position)
- (setq overlay-arrow-string "=>")
- (overlay-put overlay-arrow-overlay
- 'before-string overlay-arrow-string))
- (delete-overlay overlay-arrow-overlay)
- (setq overlay-arrow-overlay nil))))
-
- (overlay-arrow-position
- (setq overlay-arrow-overlay
- (make-overlay overlay-arrow-position overlay-arrow-position))
- (setq overlay-arrow-string "=>")
- (overlay-put overlay-arrow-overlay 'before-string
overlay-arrow-string)))
-
- ;; `compilation-context-lines' isn't t, or we've got a left
- ;; fringe, so remove any overlay arrow.
- (when (overlayp overlay-arrow-overlay)
- (setq overlay-arrow-string "")
- (delete-overlay overlay-arrow-overlay)
- (setq overlay-arrow-overlay nil)))))
+ (with-selected-window w ; So the later `goto-char' will work.
+ (with-current-buffer (window-buffer w)
+ (if (and (eq compilation-context-lines t)
+ (equal (car (window-fringes w)) 0)) ; No left fringe
+ ;; Insert a before-string overlay at the beginning of the line
+ ;; pointed to by `overlay-arrow-position', such that it will
+ ;; display in a 2-character margin.
+ (progn
+ (cond
+ ((overlayp compilation-arrow-overlay)
+ (when (not (eq (overlay-start compilation-arrow-overlay)
+ overlay-arrow-position))
+ (if overlay-arrow-position
+ (move-overlay compilation-arrow-overlay
+ overlay-arrow-position overlay-arrow-position)
+ (compilation-tear-down-arrow-spec-in-margin))))
+
+ (overlay-arrow-position
+ (setq compilation-arrow-overlay
+ (make-overlay overlay-arrow-position
overlay-arrow-position))
+ (compilation-set-up-arrow-spec-in-margin)))
+ ;; Ensure that the "=>" remains in the window by causing
+ ;; the window to be scrolled, if needed.
+ (goto-char (overlay-start compilation-arrow-overlay)))
+
+ ;; `compilation-context-lines' isn't t, or we've got a left
+ ;; fringe, so remove any overlay arrow.
+ (when (overlayp compilation-arrow-overlay)
+ (compilation-tear-down-arrow-spec-in-margin))))))
(defvar next-error-highlight-timer)
--
Alan Mackenzie (Nuremberg, Germany).
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Stefan Monnier, 2019/08/25
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Alan Mackenzie, 2019/08/25
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Eli Zaretskii, 2019/08/25
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Alan Mackenzie, 2019/08/26
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Eli Zaretskii, 2019/08/26
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Alan Mackenzie, 2019/08/27
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Eli Zaretskii, 2019/08/29
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Alan Mackenzie, 2019/08/31
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Eli Zaretskii, 2019/08/31
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling,
Alan Mackenzie <=
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Eli Zaretskii, 2019/08/27
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Stefan Monnier, 2019/08/27
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Stefan Monnier, 2019/08/27
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Alan Mackenzie, 2019/08/31
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, martin rudalics, 2019/08/31
- Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Alan Mackenzie, 2019/08/31
Re: [Emacs-diffs] master 29d1c72: Introduce new value t for compilation-context-lines to eliminate scrolling, Stefan Monnier, 2019/08/25