Line numbers still corrupting describe-mode
dzoep opened this issue · comments
((alist-get 'racket-mode package-alist) #s(package-desc racket-mode (20231109 1607) "Racket editing, REPL, and more" ((emacs (25 1))) nil nil "/home/joe/.emacs.d/elpa/racket-mode-20231109.1607" ((:url . "https://www.racket-mode.com/") (:maintainer "Greg Hendershott") (:maintainers ("Greg Hendershott")) (:authors ("Greg Hendershott" . "racket-mode-author@greghendershott.com")) (:commit . "51535efa5202c422eebaff01652cea9b83bfb200")) nil)) ((emacs-version "29.1") (system-type gnu/linux) (x-gtk-use-system-tooltips t) (major-mode help-mode) (racket--el-source-dir "/home/joe/.emacs.d/elpa/racket-mode-20231109.1607/") (racket--rkt-source-dir "/home/joe/.emacs.d/elpa/racket-mode-20231109.1607/racket/") (racket-program "racket") (racket-command-timeout 10) (racket-path-from-emacs-to-racket-function UNDEFINED) (racket-path-from-racket-to-emacs-function UNDEFINED) (racket-browse-url-function racket-browse-url-using-temporary-file) (racket-documentation-search-location "https://docs.racket-lang.org/search/index.html?q=%s") (racket-xp-after-change-refresh-delay 1) (racket-xp-mode-lighter (:eval (racket--xp-mode-lighter))) (racket-xp-highlight-unused-regexp "^[^_]") (racket-repl-buffer-name-function nil) (racket-submodules-to-run ((test) (main))) (racket-memory-limit 2048) (racket-error-context medium) (racket-repl-history-directory "~/.emacs.d/racket-mode/") (racket-history-filter-regexp "\\`\\s *\\'") (racket-images-inline t) (racket-imagemagick-props nil) (racket-images-keep-last 100) (racket-images-system-viewer "display") (racket-pretty-print t) (racket-use-repl-submit-predicate nil) (racket-pretty-print t) (racket-indent-curly-as-sequence t) (racket-indent-sequence-depth 0) (racket-pretty-lambda nil) (racket-smart-open-bracket-enable nil) (racket-module-forms "\\s(\\(?:module[*+]?\\|library\\)") (racket-logger-config ((cm-accomplice . warning) (GC . info) (module-prefetch . warning) (optimizer . info) (racket/contract . error) (racket-mode-debugger . info) (sequence-specialization . info) (* . fatal))) (racket-show-functions (racket-show-pseudo-tooltip))) (enabled-minor-modes (auto-composition-mode) (auto-compression-mode) (auto-encryption-mode) (auto-fill-mode) (auto-save-mode) (blink-cursor-mode) (buffer-read-only) (column-number-mode) (electric-indent-mode) (file-name-shadow-mode) (font-lock-mode) (global-eldoc-mode) (global-font-lock-mode) (indent-tabs-mode) (isearch-fold-quotes-mode) (line-number-mode) (mouse-wheel-mode) (semantic-minor-modes-format) (shell-dirtrack-mode) (show-paren-mode) (tooltip-mode) (transient-mark-mode)) (disabled-minor-modes (abbrev-mode) (auto-fill-function) (auto-save-visited-mode) (buffer-face-mode) (button-mode) (cl-old-struct-compat-mode) (comint-fontify-input-mode) (compilation-minor-mode) (compilation-shell-minor-mode) (completion-in-region-mode) (context-menu-mode) (cursor-face-highlight-mode) (defining-kbd-macro) (diff-auto-refine-mode) (diff-minor-mode) (dired-hide-details-mode) (dired-isearch-filenames-mode) (eldoc-mode) (electric-layout-mode) (electric-quote-mode) (global-prettify-symbols-mode) (global-semantic-highlight-edits-mode) (global-semantic-highlight-func-mode) (global-semantic-show-parser-state-mode) (global-semantic-show-unmatched-syntax-mode) (global-semantic-stickyfunc-mode) (global-visual-line-mode) (horizontal-scroll-bar-mode) (hs-minor-mode) (isearch-mode) (jit-lock-debug-mode) (lock-file-mode) (lost-selection-mode) (menu-bar-mode) (next-error-follow-minor-mode) (overwrite-mode) (paragraph-indent-minor-mode) (prettify-symbols-mode) (racket-smart-open-bracket-mode) (racket-xp-mode) (read-extended-command-mode) (semantic-highlight-edits-mode) (semantic-highlight-func-mode) (semantic-mode) (semantic-show-parser-state-mode) (semantic-show-unmatched-syntax-mode) (semantic-stickyfunc-mode) (sh-electric-here-document-mode) (shell-highlight-undef-mode) (size-indication-mode) (tab-bar-history-mode) (tab-bar-mode) (temp-buffer-resize-mode) (text-scale-mode) (tool-bar-mode) (treesit-explore-mode) (treesit-inspect-mode) (undelete-frame-mode) (url-handler-mode) (use-hard-newlines) (vc-dir-git-mode) (view-mode) (visible-mode) (visual-line-mode) (window-divider-mode) (xref-etags-mode))
How to reproduce:
Install the default emacs in Ubuntu 23.10: 1:29.1+1-5ubuntu1
Follow the instructions to install racket-mode from melpa using normal package-install as normal user.
Probably not related, but I am also using:
(require 'racket-xp)
(add-hook 'racket-mode-hook #'racket-xp-mode)
When I use c-c c-. on a documented symbol, I get:
Then in the describe buffer I do: display-line-numbers-mode
It responds: Display-Line-Numbers mode enabled in current buffer
And, of course, nothing changes.
Then I run it again: display-line-numbers-mode
Display-Line-Numbers mode disabled in current buffer
And then everything is OK.
It looks like there is some issue with the way racket-mode disables the new display-line-numbers-mode. Judging from the messages, it is disabled - but apparently not "fully".
This is similar to #627 and I have confirmed that the patch fixing that issue is part of the elisp code I am running by using the latest version of racket-mode from melpa.
This is weird timing. Before yesterday, to check out your report, I would have just re-built Emacs from source, to try this for 29.1+ (more like 30.0.50 at this point).
But I just wiped Ubuntu from my laptop and replaced it with Debian 12 yesterday.
When migrating I didn't preserve Emacs-built-from-source, figuring I there might be different builds deps, and I could just git pull and build again. Which I can. (Or try 29.1 from flatpak.) But I'm kind of overwhelmed with installing and configuring and building things (e.g. Racket) from source. I might need a day or two.
Meanwhile, I have Emacs 28.2 pre-built from Debian 12 repos. An armchair inventory:
-
line-numbers-mode
is a red herring; that's simply about whether line numbers are shown down in the mode line. -
linum-mode
is (as the kids say) the OG implemented in Emacs Lisp. Potentially slow, especially for big buffers. -
The shinier
display-line-numbers-mode
is a wrapper around a C variabledisplay-line-numbers
. Looking at the docs for that, I notice:
Lisp programs can disable display of a line number of a particular
buffer line by putting thedisplay-line-numbers-disable
text property
or overlay property on the first visible character of that line.
Maybe, for belt+suspenders, I should do that, in addition to (linum-mode -1)
and (display-line-numbers-mode -1)
which ought to work and I'm curious to learn why someday.
Adding (display-line-numbers-mode -1
fixes it for me.
The original code in racket-describe.el
added in #627 is:
(cl-macrolet ((disable (id) `(and (boundp ',id) ,id (fboundp ',id) (,id -1))))
(disable linum-mode)
(disable display-line-numbers-mode))
I've patched my local .emacs.d/elpa/racket-mode-20231109.1607/racket-describe.el
to try it out:
(cl-macrolet ((disable (id) `(and (boundp ',id) ,id (fboundp ',id) (,id -1))))
(disable linum-mode)
(disable display-line-numbers-mode)
(display-line-numbers-mode -1))
And now there is no need to enable/disable the display-line-numbers-mode in the describe buffer and the lines get wrapped around correctly.
I also tried removing the original (disable display-line-numbers-mode)
and apparently it's redundant with the -1 one.
Although maybe the macrolet
is too clever, IIRC the point was that display-line-numbers-mode
might not be defined in older Emacs. Even with the older linum-mode
-- although it might be included, it might not be loaded if the user hasn't activated the mode.
So that's why the boundp
and fboundp
stuff.
And why I think we can't just call (display-line-numbers-mode -1)
-- not quite that simple.
Maybe my disable
macro could be simpler. It's relying on the fact that minor modes (usually) define a variable and function with the same name (Emacs Lisp is a "lisp2"). So the variable says if the mode is enabled or not, and the function is how you turn on or off (1 or -1 arg).
So maybe it could just be:
(disable (id) `(and (fboundp ',id) (,id -1)))
i.e. if id
is bound as a function, call it with -1 to disable. This should be harmless if the mode is already off.
Maybe the simpler macro would even fix this problem -- maybe something changed in 29.1 such that display-line-numbers-mode
, the variable, is not reliably boundp
or reliably non-nil (??).
Since it's simpler, it could also not be a macro anymore. We could juust write out something like:
(when (fboundp 'linum-mode) (linum-mode -1))
(when (fboundp 'display-line-numbers-mode) (display-line-numbers-mode -1))
p.s. I suppose I could also just (setq truncate-lines t)
-- if the lines are too long, let them flow off the right edge of the window. It's just that shr
went to so much work trying to flow it to fit nicely, it seems a shame.
It works like a charm. Thank you very much, Greg!