From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#35058: [PATCH] Use display-graphic-p in more cases Date: Sun, 07 Apr 2019 09:50:27 -0400 Message-ID: References: <8736n4ndav.fsf@gmail.com> <83tvfjgilm.fsf@gnu.org> <875zry9x94.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="21484"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 35058@debbugs.gnu.org To: Alex Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Apr 07 15:51:12 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hD8CV-0005Sh-62 for geb-bug-gnu-emacs@m.gmane.org; Sun, 07 Apr 2019 15:51:11 +0200 Original-Received: from localhost ([127.0.0.1]:39648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hD8CU-0006aC-6l for geb-bug-gnu-emacs@m.gmane.org; Sun, 07 Apr 2019 09:51:10 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:34194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hD8CN-0006Zw-QD for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2019 09:51:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hD8CM-00085h-IF for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2019 09:51:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34315) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hD8CM-00085G-AI for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2019 09:51:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hD8CM-0003i0-2p for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2019 09:51:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 Apr 2019 13:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35058 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35058-submit@debbugs.gnu.org id=B35058.155464503314215 (code B ref 35058); Sun, 07 Apr 2019 13:51:02 +0000 Original-Received: (at 35058) by debbugs.gnu.org; 7 Apr 2019 13:50:33 +0000 Original-Received: from localhost ([127.0.0.1]:47859 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hD8Br-0003hC-RW for submit@debbugs.gnu.org; Sun, 07 Apr 2019 09:50:33 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:57446) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hD8Bp-0003h3-MP for 35058@debbugs.gnu.org; Sun, 07 Apr 2019 09:50:30 -0400 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id x37DoSGn006221; Sun, 7 Apr 2019 09:50:28 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id E12AD6AD60; Sun, 7 Apr 2019 09:50:27 -0400 (EDT) In-Reply-To: <875zry9x94.fsf@gmail.com> (Alex's message of "Sun, 31 Mar 2019 22:15:35 -0600") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6519=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6519> : inlines <7048> : streams <1817973> : uri <2827783> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:157309 Archived-At: > I wasn't sure either (I merely noticed the useless memq), but I just > checked the documentation of cua-rectangle-modifier-key, which states: > > On non-window systems, always use the meta modifier. > > So I changed the eq call to display-graphics-p. Is it okay to follow the > docstring here? IIUC the idea of this var is that many of the key-bindings cua-rectangle uses (when not using the meta modifier) are not properly handled by the vast majority of text-terminals (e.g. hitting C-RET will send Emacs the same events as just hitting RET). The meta modifier (which can be accessed as an ESC prefix when needed) doesn't suffer from the same problem. >>> - (when (memq (window-system frame) '(x w32 ns)) >>> + (when (display-graphic-p frame) >>> (x-focus-frame frame)) >> I don't see what display being GUI have to do with frame focus >> redirection. > The x-focus-frame here is the GUI-specific code related to frame focus > that calls x_focus_frame, which is only defined when HAVE_WINDOW_SYSTEM > is defined. This is one of the procedures that I'm planning to rename > with a gui prefix, so I believe display-graphic-p makes sense here. Arguably, the test should be removed and the function called unconditionally (or if it's not always defined, then the test should be (fboundp 'x-focus-frame)). > The definition of blink-cursor mode states: > This command is effective only on graphical frames. On text-only > terminals, cursor blinking is controlled by the terminal." I think this description is incorrect. blink-cursor-mode works just fine (under xterm at least), with the patch below. But I think this is not just a case of "it doesn't work": cursor-blinking can be configured in xterm independently from the application, so Emacs likely should just obey that choice, by default (whereas for GUI frames, Emacs is the only one who can decide it). Stefan diff --git a/lisp/frame.el b/lisp/frame.el index 6cb1247372..c7fe316c70 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -26,6 +26,7 @@ ;;; Code: (eval-when-compile (require 'cl-lib)) +(eval-when-compile (require 'subr-x)) ;For string-trim-right (cl-defgeneric frame-creation-function (params) "Method for window-system dependent functions to create a new frame. @@ -2480,14 +2481,34 @@ blink-cursor-timer-function (when (and (> blink-cursor-blinks 0) (<= (* 2 blink-cursor-blinks) blink-cursor-blinks-done)) (blink-cursor-suspend) - (add-hook 'post-command-hook 'blink-cursor-check))) + (add-hook 'post-command-hook #'blink-cursor-check)) + ;; FIXME: Under TTYs, apparently redisplay only obeys internal-show-cursor + ;; when there is something else to update on the screen. This is arguably + ;; a bug, but in the meantime we can circumvent it here by causing an + ;; artificial update which thus "forces" a cursor update. + (when (null window-system) + (let* ((message-log-max nil) + (msg (current-message)) + ;; Construct a dummy temp message different from the current one. + ;; This message usually flashes by too quickly to be visible, but + ;; occasionally it can be noticed, so make it "inconspicuous". + ;; Not too "inconspicuous", tho: just adding or removing a SPC at the + ;; end doesn't cause an update, for example. + (dummymsg (concat (if (> (length msg) 40) + (let ((msg (string-trim-right msg))) + (if (> (length msg) 2) + (substring msg 0 -2) + msg)) + msg) "-"))) + (message "%s" dummymsg) + (if msg (message "%s" msg) (message nil))))) (defun blink-cursor-end () "Stop cursor blinking. This is installed as a pre-command hook by `blink-cursor-start'. When run, it cancels the timer `blink-cursor-timer' and removes itself as a pre-command hook." - (remove-hook 'pre-command-hook 'blink-cursor-end) + (remove-hook 'pre-command-hook #'blink-cursor-end) (internal-show-cursor nil t) (when blink-cursor-timer (cancel-timer blink-cursor-timer) @@ -2506,15 +2527,7 @@ blink-cursor-suspend (defun blink-cursor--should-blink () "Determine whether we should be blinking. Returns whether we have any focused non-TTY frame." - (and blink-cursor-mode - (let ((frame-list (frame-list)) - (any-graphical-focused nil)) - (while frame-list - (let ((frame (pop frame-list))) - (when (and (display-graphic-p frame) (frame-focus-state frame)) - (setf any-graphical-focused t) - (setf frame-list nil)))) - any-graphical-focused))) + blink-cursor-mode) (defun blink-cursor-check () "Check if cursor blinking shall be restarted. @@ -2523,7 +2536,7 @@ blink-cursor-check `blink-cursor--should-blink' and returns its result." (let ((should-blink (blink-cursor--should-blink))) (when (and should-blink (not blink-cursor-idle-timer)) - (remove-hook 'post-command-hook 'blink-cursor-check) + (remove-hook 'post-command-hook #'blink-cursor-check) (blink-cursor--start-idle-timer)) should-blink))