From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#32744: There seems to be a bug in current-column in character mode Date: Mon, 17 Sep 2018 17:43:02 +0300 Message-ID: <83o9cwgp6x.fsf@gnu.org> References: <83y3c1gyer.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1537195330 32232 195.159.176.226 (17 Sep 2018 14:42:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 17 Sep 2018 14:42:10 +0000 (UTC) Cc: 32744-done@debbugs.gnu.org To: Kalman Reti Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Sep 17 16:42:06 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1uiy-0008D6-Ar for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Sep 2018 16:42:04 +0200 Original-Received: from localhost ([::1]:35900 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1ul4-0001IN-Ne for geb-bug-gnu-emacs@m.gmane.org; Mon, 17 Sep 2018 10:44:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1ukw-0001GM-KY for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 10:44:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1uks-000866-H2 for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 10:44:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38985) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g1uks-00085V-B8 for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 10:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1g1uks-00063r-9v for bug-gnu-emacs@gnu.org; Mon, 17 Sep 2018 10:44:02 -0400 Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Mon, 17 Sep 2018 14:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 32744 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 32744@debbugs.gnu.org, eliz@gnu.org, kalman.reti@gmail.com Original-Received: via spool by 32744-done@debbugs.gnu.org id=D32744.153719539823235 (code D ref 32744); Mon, 17 Sep 2018 14:44:02 +0000 Original-Received: (at 32744-done) by debbugs.gnu.org; 17 Sep 2018 14:43:18 +0000 Original-Received: from localhost ([127.0.0.1]:43242 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1ukA-00062g-6r for submit@debbugs.gnu.org; Mon, 17 Sep 2018 10:43:18 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53255) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1uk9-00062U-53 for 32744-done@debbugs.gnu.org; Mon, 17 Sep 2018 10:43:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1ujz-0006AF-OH for 32744-done@debbugs.gnu.org; Mon, 17 Sep 2018 10:43:11 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:51266) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1ujz-00069Z-Ir; Mon, 17 Sep 2018 10:43:07 -0400 Original-Received: from [176.228.60.248] (port=1342 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1g1ujy-0000Pu-9u; Mon, 17 Sep 2018 10:43:07 -0400 In-reply-to: (message from Kalman Reti on Sun, 16 Sep 2018 19:44:33 -0400) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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: 208.118.235.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:150368 Archived-At: > From: Kalman Reti > Date: Sun, 16 Sep 2018 19:44:33 -0400 > Cc: 32744@debbugs.gnu.org > > I get 8 in GUI frames as well. > > The display spec (space :width 7) means 7 times the width of the > default face's font. So if your default GUI font is monospaced, you > should get 8 in both GUI and text-mode frames. > > So I'm unsure how come you get 2 in GUI mode. Maybe you've omitted > some important detail in the reproducer. > > I apologize; you are correct, it gets 8 in gui mode as well. I must have been confused about which window > was running which version of emacs while I was experimenting. > > But is that the correct value? The bubbles game code clearly wants it to mean 'the number of forward-chars I > have to do from the beginning of the line to get here' not 'what column does it visually look like I'm on'. > > The doc string for the function doesn't clarify the intended meaning. > > If you do m-x bubbles immediately followed by m-: (current-column) it returns 1 in the gui case but a number > larger than one (which depends upon the :width keyword of the wide-displaying space), but for the game to > work in the character case it needs to return 1. It's a bug in bubbles.el, now fixed on the emacs-26 branch. The patch is below, so you can apply it locally if you want. The patch does some cleanup, so it might not be easy to spot the crucial problem it fixes. The root cause of the bug was that bubbles--initialize had 2 code paths in it: one for GUI frames (which worked), and another for TTY frames (which didn't, and it seems to me that no one has ever tried it). The GUI part computed the offsets as lists, i.e. '(N), whereas the TTY part produced just N, a simple number. And the display property 'space' treats each of these differently: '(N) is treated as pixel width, while N is treated as a multiple of the default character width (your example only used the N form, so it produced 8 instead of 1 from current-column). Once we produce '(N) both in GUI and in TTY frames, the game works in both. Here's the patch I promised; I'm closing the bug report. diff --git a/lisp/play/bubbles.el b/lisp/play/bubbles.el index e30838d..ee2135b 100644 --- a/lisp/play/bubbles.el +++ b/lisp/play/bubbles.el @@ -250,10 +250,10 @@ bubbles--images-ok "Indicate whether images have been created successfully.") (defvar bubbles--col-offset 0 - "Horizontal offset for centering the bubbles grid.") + "Horizontal offset for centering the bubbles grid, in pixels.") (defvar bubbles--row-offset 0 - "Vertical offset for centering the bubbles grid.") + "Vertical offset for centering the bubbles grid, in pixels.") (defvar bubbles--save-data nil "List containing bubbles save data (SCORE BUFFERCONTENTS).") @@ -960,33 +960,26 @@ bubbles-quit (defun bubbles--compute-offsets () "Update horizontal and vertical offsets for centering the bubbles grid. Set `bubbles--col-offset' and `bubbles--row-offset'." - (cond ((and (display-images-p) - bubbles--images-ok - (not (eq bubbles-graphics-theme 'ascii)) - (fboundp 'window-inside-pixel-edges)) - ;; compute offset in units of pixels - (let ((bubbles--image-size - (car (image-size (car bubbles--images) t)))) - (setq bubbles--col-offset - (list - (max 0 (/ (- (nth 2 (window-inside-pixel-edges)) - (nth 0 (window-inside-pixel-edges)) - (* ( + bubbles--image-size 2) ;; margin - (bubbles--grid-width))) 2)))) - (setq bubbles--row-offset - (list - (max 0 (/ (- (nth 3 (window-inside-pixel-edges)) - (nth 1 (window-inside-pixel-edges)) - (* (+ bubbles--image-size 1) ;; margin - (bubbles--grid-height))) 2)))))) - (t - ;; compute offset in units of chars - (setq bubbles--col-offset - (max 0 (/ (- (window-width) - (bubbles--grid-width)) 2))) - (setq bubbles--row-offset - (max 0 (/ (- (window-height) - (bubbles--grid-height) 2) 2)))))) + (let* ((use-images-p (and (display-images-p) + bubbles--images-ok + (not (eq bubbles-graphics-theme 'ascii)))) + (bubbles--image-size + (if use-images-p (car (image-size (car bubbles--images) t)) 1)) + ;; In GUI mode, leave thin margins around the images. + (image-hor-size + (if use-images-p (+ bubbles--image-size 2) bubbles--image-size)) + (image-vert-size + (if use-images-p (1+ bubbles--image-size) bubbles--image-size))) + (setq bubbles--col-offset + (max 0 (/ (- (nth 2 (window-body-pixel-edges)) + (nth 0 (window-body-pixel-edges)) + (* image-hor-size (bubbles--grid-width))) + 2))) + (setq bubbles--row-offset + (max 0 (/ (- (nth 3 (window-body-pixel-edges)) + (nth 1 (window-body-pixel-edges)) + (* image-vert-size (bubbles--grid-height))) + 2))))) (defun bubbles--remove-overlays () "Remove all overlays." @@ -1007,7 +1000,8 @@ bubbles--initialize (insert " ") (put-text-property (point-min) (point) 'display - (cons 'space (list :height bubbles--row-offset))) + (cons 'space (list :height + (list bubbles--row-offset)))) (insert "\n") (let ((max-char (length (bubbles--colors)))) (dotimes (i (bubbles--grid-height)) @@ -1015,7 +1009,8 @@ bubbles--initialize (insert " ") (put-text-property p (point) 'display - (cons 'space (list :width bubbles--col-offset)))) + (cons 'space (list :width + (list bubbles--col-offset))))) (dotimes (j (bubbles--grid-width)) (let* ((index (random max-char)) (char (nth index bubbles-chars))) @@ -1025,7 +1020,8 @@ bubbles--initialize (insert "\n ") (put-text-property (1- (point)) (point) 'display - (cons 'space (list :width bubbles--col-offset)))) + (cons 'space (list :width + (list bubbles--col-offset))))) (put-text-property (point-min) (point-max) 'pointer 'arrow)) (bubbles-mode) (bubbles--reset-score) @@ -1177,7 +1173,7 @@ bubbles--show-scores (insert " ") (put-text-property (1- (point)) (point) 'display - (cons 'space (list :width bubbles--col-offset))) + (cons 'space (list :width (list bubbles--col-offset)))) (insert (format "Score: %4d" bubbles--score)) (put-text-property pos (point) 'status t)))) @@ -1197,7 +1193,7 @@ bubbles--game-over (insert "\n ") (put-text-property (1- (point)) (point) 'display - (cons 'space (list :width bubbles--col-offset))) + (cons 'space (list :width (list bubbles--col-offset)))) (insert "Game Over!")) ;; save score (gamegrid-add-score (format "bubbles-%s-%d-%d-%d-scores"