greghendershott / racket-mode

Emacs major and minor modes for Racket: edit, REPL, check-syntax, debug, profile, packages, and more.
https://www.racket-mode.com/
GNU General Public License v3.0
682 stars 93 forks source link

`beginning-of-defun` doesn't work properly when narrowed #694

Closed leungbk closed 11 months ago

leungbk commented 11 months ago

Given an init.el that looks like

(let ((bootstrap-file (concat user-emacs-directory "straight/repos/straight.el/bootstrap.el"))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(straight-use-package 'use-package)
(setq straight-use-package-by-default t)

(use-package racket-mode)

and a Racket file

#lang racket

(define (hello _)
  42)

(define (bye-bye _)
  42)

I find that when I C-x n d within either function and try to use beginning-of-defun, point does not move where I expect it to.

Package

metadata
nil
package-archives
(("gnu" . "https://elpa.gnu.org/packages/")
 ("nongnu" . "https://elpa.nongnu.org/nongnu/"))
racket--el-source-dir
"/home/brian/.config/emacs/straight/build/racket-mode/"
racket--rkt-source-dir
"/home/brian/.config/emacs/straight/build/racket-mode/racket/"

System values

emacs-version
"30.0.50"
major-mode
help-mode
system-type
gnu/linux
x-gtk-use-system-tooltips
t
display-graphic-p
nil

Buffer values

after-change-functions
nil
before-change-functions
nil
completion-at-point-functions
(tags-completion-at-point-function)
eldoc-documentation-function
eldoc-documentation-default
font-lock-defaults
nil
pre-command-hook
(tooltip-hide)
post-command-hook
(global-font-lock-mode-check-buffers global-eldoc-mode-check-buffers
                     mode-local-post-major-mode-change)
post-self-insert-hook
(electric-indent-post-self-insert-function
 blink-paren-post-self-insert-function)
xref-backend-functions
(etags--xref-backend)

Racket Mode values

racket--cmd-open-p
nil
racket-after-run-hook
nil
racket-back-end-configurations
((:directory "/" :racket-program nil :remote-source-dir nil
         :restart-watch-directories nil :windows nil))
racket-before-run-hook
(racket-ansi-color-context-reset)
racket-browse-url-function
racket-browse-url-using-temporary-file
racket-command-timeout
10
racket-documentation-search-location
"https://docs.racket-lang.org/search/index.html?q=%s"
racket-error-context
medium
racket-hash-lang-token-face-alist
((constant . font-lock-constant-face) (error . error)
 (other . font-lock-doc-face) (keyword . font-lock-keyword-face)
 (hash-colon-keyword . racket-keyword-argument-face)
 (at . font-lock-doc-face))
racket-history-filter-regexp
"\\`\\s *\\'"
racket-imagemagick-props
nil
racket-images-inline
t
racket-images-keep-last
100
racket-images-system-viewer
"display"
racket-indent-curly-as-sequence
t
racket-indent-sequence-depth
0
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-memory-limit
2048
racket-mode-hook
nil
racket-module-forms
"\\s(\\(?:module[*+]?\\|library\\)"
racket-pretty-lambda
nil
racket-pretty-print
t
racket-program
"racket"
racket-repl-buffer-name-function
nil
racket-repl-command-file
"/home/brian/.config/emacs/racket-mode/repl.rkt"
racket-repl-history-directory
"~/.config/emacs/racket-mode/"
racket-repl-mode-hook
nil
racket-sexp-comment-fade
0.5
racket-shell-or-terminal-function
racket-shell
racket-show-functions
(racket-show-pseudo-tooltip)
racket-smart-open-bracket-enable
nil
racket-submodules-to-run
((test) (main))
racket-use-repl-submit-predicate
nil
racket-xp-add-binding-faces
nil
racket-xp-after-change-refresh-delay
1
racket-xp-highlight-unused-regexp
"^[^_]"
racket-xp-mode-lighter
(:eval (racket--xp-mode-lighter))

Minor modes

enabled
((auto-composition-mode) (auto-compression-mode)
 (auto-encryption-mode) (blink-cursor-mode) (buffer-read-only)
 (electric-indent-mode) (file-name-shadow-mode) (font-lock-mode)
 (global-eldoc-mode) (global-font-lock-mode) (gpm-mouse-mode)
 (indent-tabs-mode) (isearch-fold-quotes-mode) (line-number-mode)
 (menu-bar-mode) (minibuffer-regexp-mode) (mouse-wheel-mode)
 (semantic-minor-modes-format) (show-paren-mode)
 (straight-package-neutering-mode) (straight-use-package-mode)
 (tool-bar-mode) (tooltip-mode) (transient-mark-mode))
Disabled minor modes
disabled
((abbrev-mode) (auto-fill-function) (auto-fill-mode) (auto-save-mode)
 (auto-save-visited-mode) (buffer-face-mode) (button-mode)
 (cl-old-struct-compat-mode) (column-number-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)
 (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)
 (modifier-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-dirtrack-mode)
 (shell-highlight-undef-mode) (size-indication-mode)
 (straight-live-modifications-mode) (straight-symlink-emulation-mode)
 (tab-bar-history-mode) (tab-bar-mode) (temp-buffer-resize-mode)
 (text-scale-mode) (treesit-explore-mode) (treesit-inspect-mode)
 (undelete-frame-mode) (url-handler-mode) (use-hard-newlines)
 (view-mode) (visible-mode) (visual-line-mode) (window-divider-mode)
 (xref-etags-mode))
leungbk commented 11 months ago

Some other unexpected behavior I noticed: after running C-c C-c on the buffer, when the buffer is narrowed to either function, C-M-x does not work when point is on the first line of either define; however, when on the second line of either function, C-M-x works fine.

greghendershott commented 11 months ago

Hmm. Unlike #693, I can't seem to reproduce this, so far. For me:

I'll try with Emacs built from source, later.

leungbk commented 11 months ago

Thanks for your reply!

Hmm. Unlike #693, I can't seem to reproduce this, so far. For me:

* C-M-a always moves point before the open paren of the definition.

Hmm, I can't seem to get the expected behavior; I also tried on Emacs 28.2 and 29.1 just now and saw no change. Even when manually typing out M-x beginning-of-defun, the observed behavior looks indistinguishable from that of backward-sexp.

* C-M-x does work on either line.

After I C-c C-c, running narrow-to-defun followed by C-M-x when point is anywhere on the first line of the second define yields this in the *Racket REPL*:

Welcome to Racket v8.11.1 [cs].
————— run hello.rkt —————
hello.rkt> 
racket-mode-repl::10: _: wildcard not allowed as an expression
  in: _
hello.rkt> 

Feel free to let me know if there's any other info I can provide.

greghendershott commented 11 months ago

I tried again with Emacs built from source, c. couple weeks ago (GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.16.0) of 2023-12-07). But same result: still can't reproduce. :(

FWIW I run it with ~/src/emacs/src/emacs -L ~/src/elisp/racket-mode/ -Q and manually M-x load-file the racket-mode.el file.

Then I visit issue-694.rkt file (your example above). racket-mode is enabled automatically. I try your steps. Everything works as expected.


Even with -Q my enabled minor modes are:

((auto-composition-mode) (auto-compression-mode)
 (auto-encryption-mode) (blink-cursor-mode) (buffer-read-only)
 (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) (menu-bar-mode)
 (minibuffer-regexp-mode) (mouse-wheel-mode)
 (semantic-minor-modes-format) (show-paren-mode) (tool-bar-mode)
 (tooltip-mode) (transient-mark-mode))

Yours are:

((auto-composition-mode) (auto-compression-mode)
 (auto-encryption-mode) (blink-cursor-mode) (buffer-read-only)
 (electric-indent-mode) (file-name-shadow-mode) (font-lock-mode)
 (global-eldoc-mode) (global-font-lock-mode) (gpm-mouse-mode)
 (indent-tabs-mode) (isearch-fold-quotes-mode) (line-number-mode)
 (menu-bar-mode) (minibuffer-regexp-mode) (mouse-wheel-mode)
 (semantic-minor-modes-format) (show-paren-mode)
 (straight-package-neutering-mode) (straight-use-package-mode)
 (tool-bar-mode) (tooltip-mode) (transient-mark-mode))

Those are nearly identical -- if I'm eyeballing it correctly, you have gpm-mouse-mode enabled which I don't -- so I am super stumped...

(This feels like one of those bugs that will turn out to be either amazingly subtle, or, blatantly obvious/simple in hindsight, but nothing in between.)

greghendershott commented 11 months ago

p.s. FWIW I build with the following on Debian 12 (e.g. no libjit ergo no native-comp):

## Clone
git clone git://git.savannah.gnu.org/emacs.git

## Deps
sudo apt install \
  autoconf \
  build-essential \
  libgtk-3-dev \
  libgnutls28-dev \
  libtiff5-dev \
  libgif-dev \
  libjpeg-dev \
  libpng-dev \
  libxpm-dev \
  libxml2-dev \
  libncurses-dev \
  texinfo

## Build
./autogen.sh
./configure
make --jobs=$(nproc)
greghendershott commented 11 months ago

blatantly obvious/simple in hindsight

This. I had a tentative fix for #693. I thought I had reverted that, while trying to reproduce this -- but I hadn't really.

That fix for #693 turns out to fix this, too, in a way I didn't expect.

I am so sorry for the noise!

I'll push a commit to fix both issues... but since I'm being so dumb today, I'll slow down and triple check things...