all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kiso Katsuyuki <katsuyuki2388@gmail.com>
To: Juri Linkov <juri@linkov.net>
Cc: emacs-devel@gnu.org
Subject: Re: Selecting *Compile-log* buffer automatically
Date: Sun, 24 Dec 2023 06:51:23 -0600	[thread overview]
Message-ID: <CAOq35dgmnuyzCFxBsKf_YOnBPPw4VURq164D8aaBg5mDi4s0tA@mail.gmail.com> (raw)
In-Reply-To: <86wmt4hl5e.fsf@mail.linkov.net>


[-- Attachment #1.1: Type: text/plain, Size: 1915 bytes --]

>>>I believe this should be customizable with something like
>>>
>>>  (setopt display-buffer-alist
>>>   '(("\\*Compile-log\\*" nil (select-window . t))))
>>
>> Thank you for the advice, but I tried this and it didn't work.
>> *Compile-log* buffer isn't selected.
>> I used emacs 29.1 with no init files loaded.
>
>This feature was discussed in bug#33258 and bug#46034,
>but not yet implemented.  It should be easy to implement
>exactly the same way as 'windmove-display-in-direction'
>selects the old or new window in 'post-command-hook'.
>Ok, I will post a patch to bug-gnu-emacs.

There seems to be another problem with using display-buffer-alist.
byte-compile-file repeats byte-compile, display-warning (this uses
display-buffer)
for each S-expression. Selecting *Compile-log* buffer before finishing
byte-compiling the last
S-expression causes an error. I checked the error using

(defun select-visible-warning-buffer (_type _message &optional _level
buffer-name)
  "Select the visible warning buffer"
  (unless buffer-name
    (setq buffer-name "*Warnings*"))
  (let ((window (get-buffer-window (get-buffer buffer-name))))
    (if window (select-window window))))

(advice-add 'display-warning :after #'select-visible-warning-buffer)

, and byte-compile causes "Error: End of file during parsing".

display-buffer-alist should affect every display-buffer, so I think
it leads to the same error.

I think selecting the *Compile-Log* buffer separately from display-buffer
is easier. I made the attached patch to select *Compile-Log* buffer
for emacs 29.1 bytecomp.el.


>> I'll consider a different way.
>
>Until this is pushed, you could use such a simple advice
>that does the same:
>
>(define-advice dired-do-byte-compile (:after (&rest _args) select-window)
>  (when-let ((window (get-buffer-window "*Compile-Log*" 0)))
>    (select-window window)))

Thanks. I referred to this when I made the above patch.

[-- Attachment #1.2: Type: text/html, Size: 2331 bytes --]

[-- Attachment #2: bytecomp.patch --]
[-- Type: text/x-patch, Size: 2253 bytes --]

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 5df1205869c..b9b5b93d1a2 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1311,10 +1311,13 @@ where the problem was detected.  FILL is a prefix as in
 `warning-fill-prefix'.  LEVEL is the level of the
 problem (`:warning' or `:error').  FILL and LEVEL may be nil.")
 
+(defvar byte-compile-warning-flag nil)
+
 (defun byte-compile-log-warning (string &optional fill level)
   "Log a byte-compilation warning.
 STRING, FILL and LEVEL are as described in
 `byte-compile-log-warning-function', which see."
+  (setq byte-compile-warning-flag t)
   (funcall byte-compile-log-warning-function
            string
            (or (byte-compile--warning-source-offset)
@@ -2118,6 +2121,9 @@ See also `emacs-lisp-byte-compile-and-load'."
 		 (y-or-n-p (format "Save buffer %s first? " (buffer-name b))))
 	    (with-current-buffer b (save-buffer)))))
 
+  ;; Reset the warning flag
+  (setq byte-compile-warning-flag nil)
+
   ;; Force logging of the file name for each file compiled.
   (setq byte-compile-last-logged-file nil)
   (let ((byte-compile-current-file filename)
@@ -2244,6 +2250,11 @@ See also `emacs-lisp-byte-compile-and-load'."
 			      target-file))))))
           (unless byte-native-compiling
 	    (kill-buffer (current-buffer))))
+
+	;; select the byte compile log
+	(if byte-compile-select-log-buffer
+	    (if byte-compile-warning-flag (select-visible-byte-compile-log)))
+
 	(if (and byte-compile-generate-call-tree
 		 (or (eq t byte-compile-generate-call-tree)
 		     (y-or-n-p (format "Report call tree for %s? "
@@ -2263,6 +2274,17 @@ See also `emacs-lisp-byte-compile-and-load'."
             (load target-file))
 	t))))
 
+(defcustom byte-compile-select-log-buffer nil
+  "If non-nil, the `byte-compile-log-buffer' window in the selected frame
+is selected when there are warnings."
+  :type 'boolean
+  :group 'bytecomp)
+
+(defun select-visible-byte-compile-log ()
+  "Select the visible byte compile log buffer in the selected frame"
+  (when-let ((window (get-buffer-window byte-compile-log-buffer)))
+    (select-window window)))
+
 ;;; compiling a single function
 ;;;###autoload
 (defun compile-defun (&optional arg)

  reply	other threads:[~2023-12-24 12:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-10 18:38 Selecting *Compile-log* buffer automatically Kiso Katsuyuki
2023-12-10 19:32 ` Eli Zaretskii
2023-12-11  1:07   ` Kiso Katsuyuki
2023-12-11 11:56     ` Eli Zaretskii
2023-12-17  2:22       ` Kiso Katsuyuki
2023-12-11 17:04 ` Juri Linkov
2023-12-23  8:19   ` Kiso Katsuyuki
2023-12-23 17:41     ` Juri Linkov
2023-12-24 12:51       ` Kiso Katsuyuki [this message]
2023-12-24 17:28         ` Juri Linkov
2023-12-25 13:03           ` Kiso Katsuyuki
2024-02-17 18:20             ` Kiso Katsuyuki

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOq35dgmnuyzCFxBsKf_YOnBPPw4VURq164D8aaBg5mDi4s0tA@mail.gmail.com \
    --to=katsuyuki2388@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.