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
683 stars 93 forks source link

`narrow-to-defun` doesn't work properly #693

Closed leungbk closed 11 months ago

leungbk commented 11 months ago

When I emacs -q a config containing nothing but a basic racket-mode config

(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 open a hello.rkt file

(define (hello _)
  42)

I find that C-x n d at various points in the function cuts off some unexpected text.

leungbk commented 11 months ago

I am on Emacs 30 6abea4d98d1d964c68a78cb9b5321071da851654.

greghendershott commented 11 months ago

I can reproduce this on e.g. Emacs 28.2 so it's not some sort of bleeding edge problem.

It seems to happen only when the "defun" is the first non-space thing in the file. (For example it won't happen in a "normal" file with a #lang line -- which is probably why I haven't noticed this bug in many many years.)

So on the one hand I could imagine choosing not to fix this if it risked introducing new, worse bugs.

But on the other hand I think I see where the problem is, in racket-sexp-comment-start. That seems safe to change. So I plan to do that...