* bug#32744: There seems to be a bug in current-column in character mode @ 2018-09-16 13:28 Kalman Reti 2018-09-16 17:11 ` Eli Zaretskii 0 siblings, 1 reply; 7+ messages in thread From: Kalman Reti @ 2018-09-16 13:28 UTC (permalink / raw To: 32744 [-- Attachment #1: Type: text/plain, Size: 428 bytes --] In an empty buffer, m-: of (let ((p (point))) (insert " ") (add-text-properties p (point) `(display (space :width 7))) (insert ".") (current-column)) returns 2 in gui mode but 8 in character mode of emacsen more recent than emacs 22. (I tried it in several emacs versions including the most recent 27.0.50 snapshot.) I discovered this by figuring out why the m-x bubbles game hasn't worked in character mode since emacs 22. [-- Attachment #2: Type: text/html, Size: 568 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#32744: There seems to be a bug in current-column in character mode 2018-09-16 13:28 bug#32744: There seems to be a bug in current-column in character mode Kalman Reti @ 2018-09-16 17:11 ` Eli Zaretskii [not found] ` <CAJ7Ts_161=cFRcG7oZAfjLsByzk=L8=iD+WQr-LF4z2-kWhn4w@mail.gmail.com> 0 siblings, 1 reply; 7+ messages in thread From: Eli Zaretskii @ 2018-09-16 17:11 UTC (permalink / raw To: Kalman Reti; +Cc: 32744 > From: Kalman Reti <kalman.reti@gmail.com> > Date: Sun, 16 Sep 2018 09:28:47 -0400 > > In an empty buffer, m-: of > > (let ((p (point))) (insert " ") (add-text-properties p (point) `(display (space :width 7))) (insert ".") > (current-column)) > > returns 2 in gui mode but 8 in character mode of emacsen more recent than emacs 22. (I tried it in several > emacs versions including the most recent 27.0.50 snapshot.) 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. Thanks. ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <CAJ7Ts_161=cFRcG7oZAfjLsByzk=L8=iD+WQr-LF4z2-kWhn4w@mail.gmail.com>]
[parent not found: <CAJ7Ts_22HqjfaPO7AGXRw3FS3hiH8SX4BF6DYE+YX5y8Znketg@mail.gmail.com>]
* bug#32744: There seems to be a bug in current-column in character mode [not found] ` <CAJ7Ts_22HqjfaPO7AGXRw3FS3hiH8SX4BF6DYE+YX5y8Znketg@mail.gmail.com> @ 2018-09-16 23:44 ` Kalman Reti 2018-09-17 14:43 ` Eli Zaretskii 0 siblings, 1 reply; 7+ messages in thread From: Kalman Reti @ 2018-09-16 23:44 UTC (permalink / raw To: Eli Zaretskii; +Cc: 32744 [-- Attachment #1: Type: text/plain, Size: 1540 bytes --] On Sep 16, 2018 1:12 PM, "Eli Zaretskii" <eliz@gnu.org> wrote: > From: Kalman Reti <kalman.reti@gmail.com> > Date: Sun, 16 Sep 2018 09:28:47 -0400 > > In an empty buffer, m-: of > > (let ((p (point))) (insert " ") (add-text-properties p (point) `(display (space :width 7))) (insert ".") > (current-column)) > > returns 2 in gui mode but 8 in character mode of emacsen more recent than emacs 22. (I tried it in several > emacs versions including the most recent 27.0.50 snapshot.) 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. Thanks. [-- Attachment #2: Type: text/html, Size: 2544 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#32744: There seems to be a bug in current-column in character mode 2018-09-16 23:44 ` Kalman Reti @ 2018-09-17 14:43 ` Eli Zaretskii 2018-09-17 14:54 ` Kalman Reti 0 siblings, 1 reply; 7+ messages in thread From: Eli Zaretskii @ 2018-09-17 14:43 UTC (permalink / raw To: Kalman Reti; +Cc: 32744-done > From: Kalman Reti <kalman.reti@gmail.com> > 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" ^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#32744: There seems to be a bug in current-column in character mode 2018-09-17 14:43 ` Eli Zaretskii @ 2018-09-17 14:54 ` Kalman Reti 2018-09-17 15:22 ` Eli Zaretskii 0 siblings, 1 reply; 7+ messages in thread From: Kalman Reti @ 2018-09-17 14:54 UTC (permalink / raw To: Eli Zaretskii; +Cc: 32744-done [-- Attachment #1: Type: text/plain, Size: 8083 bytes --] On Sep 17, 2018 10:43 AM, "Eli Zaretskii" <eliz@gnu.org> wrote: > From: Kalman Reti <kalman.reti@gmail.com> > 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. I think the doc string for current column should be enhanced to say what it is returning. > > 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 existing bubbles code works for both gui and character mode in emacs 22, so I'd characterize it less as a bug in bubbles as an incompatibility introduced after emacs 22. Is there some other function that will give 'how many forward-chars necessary to go from beginning of line to here? Thanks for the patch. 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" [-- Attachment #2: Type: text/html, Size: 11118 bytes --] ^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#32744: There seems to be a bug in current-column in character mode 2018-09-17 14:54 ` Kalman Reti @ 2018-09-17 15:22 ` Eli Zaretskii 2018-09-17 15:34 ` Noam Postavsky 0 siblings, 1 reply; 7+ messages in thread From: Eli Zaretskii @ 2018-09-17 15:22 UTC (permalink / raw To: Kalman Reti; +Cc: 32744 > From: Kalman Reti <kalman.reti@gmail.com> > Date: Mon, 17 Sep 2018 10:54:50 -0400 > Cc: 32744-done@debbugs.gnu.org > > > The doc string for the function doesn't clarify the intended meaning. > > I think the doc string for current column should be enhanced to say what it is returning. What would you want it to say in addition or differently to what it says now? > 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 existing bubbles code works for both gui and character mode in emacs 22, so I'd characterize it less as a > bug in bubbles as an incompatibility introduced after emacs 22. I don't see bubbles.el in any Emacs 22.x release I have here. Maybe you have some downstream distribution which backported the game from Emacs 23? I did try in Emacs 23, and I saw the same problem there. And the initial revision of bubbles.el I see in Git has the same problem on TTY frames as the one I described. Perhaps there was some bug/misfeature in current-column, which was meanwhile fixed. > Is there some other function that will give 'how many forward-chars necessary to go from beginning of line to > here? I think you want posn-actual-col-row. ^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#32744: There seems to be a bug in current-column in character mode 2018-09-17 15:22 ` Eli Zaretskii @ 2018-09-17 15:34 ` Noam Postavsky 0 siblings, 0 replies; 7+ messages in thread From: Noam Postavsky @ 2018-09-17 15:34 UTC (permalink / raw To: Eli Zaretskii; +Cc: 32744, Kalman Reti On 17 September 2018 at 11:22, Eli Zaretskii <eliz@gnu.org> wrote: >> Is there some other function that will give 'how many forward-chars necessary to go from beginning of line to >> here? > > I think you want posn-actual-col-row. Or (- (point) (line-beginning-position)) ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-09-17 15:34 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-09-16 13:28 bug#32744: There seems to be a bug in current-column in character mode Kalman Reti 2018-09-16 17:11 ` Eli Zaretskii [not found] ` <CAJ7Ts_161=cFRcG7oZAfjLsByzk=L8=iD+WQr-LF4z2-kWhn4w@mail.gmail.com> [not found] ` <CAJ7Ts_22HqjfaPO7AGXRw3FS3hiH8SX4BF6DYE+YX5y8Znketg@mail.gmail.com> 2018-09-16 23:44 ` Kalman Reti 2018-09-17 14:43 ` Eli Zaretskii 2018-09-17 14:54 ` Kalman Reti 2018-09-17 15:22 ` Eli Zaretskii 2018-09-17 15:34 ` Noam Postavsky
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).