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

Has ^M in the racket-steppper-mode buffer? #598

Closed chansey97 closed 2 years ago

chansey97 commented 2 years ago

I am trying to use macro expander in racket-mode.

Everything is fine, except that the stepper buffer will display an extra ^M

For example,

#lang racket

(define-syntax-rule (baz (arg1 ...) (arg2 ...) ) 
  (list '(+ 42 arg1 arg2) ...))

(baz (1 2) (11 22))

Placing the mouse cursor at (baz (1 2) (11 22))| and M-x racket-expand-last-sexp, the stepper buffer will show:

racket-mode

Thank you for this great work.

My racket-mode version is racket-mode-20220216.1917 from elpa, operation system is windows 7, Racket v8.0 [bc].

racket-bug-report:

((alist-get 'racket-mode package-alist))
((emacs-version "27.2")
 (system-type windows-nt)
 (x-gtk-use-system-tooltips UNDEFINED)
 (major-mode racket-mode)
 (racket--el-source-dir "c:/Users/Chansey/AppData/Roaming/.emacs.d/site-lisp/racket-mode-20220216.1917/")
 (racket--rkt-source-dir "c:/Users/Chansey/AppData/Roaming/.emacs.d/site-lisp/racket-mode-20220216.1917/racket/")
 (racket-program "C:\\Program Files\\Racket\\Racket.exe")
 (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)
   (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)
 (back-button-mode)
 (blink-cursor-mode)
 (cl-old-struct-compat-mode)
 (column-number-mode)
 (company-mode)
 (company-quickhelp-local-mode)
 (company-quickhelp-mode)
 (cua-mode)
 (delete-selection-mode)
 (desktop-save-mode)
 (electric-indent-mode)
 (file-name-shadow-mode)
 (font-lock-mode)
 (global-auto-revert-mode)
 (global-company-mode)
 (global-eldoc-mode)
 (global-font-lock-mode)
 (global-hl-line-mode)
 (global-linum-mode)
 (global-page-break-lines-mode)
 (global-symbol-overlay-mode)
 (global-undo-tree-mode)
 (goto-address-prog-mode)
 (hs-minor-mode)
 (ivy-mode)
 (line-number-mode)
 (linum-mode)
 (menu-bar-mode)
 (mode-icons-mode)
 (mouse-wheel-mode)
 (paredit-mode)
 (popwin-mode)
 (projectile-mode)
 (racket-xp-mode)
 (recentf-mode)
 (save-place-mode)
 (savehist-mode)
 (semantic-minor-modes-format)
 (shell-dirtrack-mode)
 (show-paren-mode)
 (symbol-overlay-mode)
 (tabbar-mode)
 (tabbar-mwheel-mode)
 (tool-bar-mode)
 (tooltip-mode)
 (transient-mark-mode)
 (treemacs-filewatch-mode)
 (treemacs-fringe-indicator-mode)
 (undo-tree-mode)
 (yas-global-mode)
 (yas-minor-mode))
(disabled-minor-modes
 (abbrev-mode)
 (ace-window-display-mode)
 (ace-window-mode)
 (auto-fill-function)
 (auto-revert-mode)
 (auto-revert-tail-mode)
 (auto-save-visited-mode)
 (avy-linum-mode)
 (buffer-face-mode)
 (buffer-read-only)
 (company-search-mode)
 (compilation-minor-mode)
 (compilation-shell-minor-mode)
 (completion-in-region-mode)
 (counsel-mode)
 (defining-kbd-macro)
 (diff-auto-refine-mode)
 (diff-minor-mode)
 (dired-hide-details-mode)
 (drag-stuff-global-mode)
 (drag-stuff-mode)
 (eldoc-mode)
 (electric-layout-mode)
 (electric-quote-mode)
 (flymake-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)
 (goto-address-mode)
 (haskell-indentation-mode)
 (hl-line-mode)
 (horizontal-scroll-bar-mode)
 (ibuffer-auto-mode)
 (isearch-mode)
 (jit-lock-debug-mode)
 (next-error-follow-minor-mode)
 (outline-minor-mode)
 (overwrite-mode)
 (page-break-lines-mode)
 (paragraph-indent-minor-mode)
 (prettify-symbols-mode)
 (racket-debug-mode)
 (racket-smart-open-bracket-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)
 (show-smartparens-global-mode)
 (show-smartparens-mode)
 (size-indication-mode)
 (smartparens-global-mode)
 (smartparens-global-strict-mode)
 (smartparens-mode)
 (smartparens-strict-mode)
 (sql-upcase-mode)
 (tab-bar-history-mode)
 (tab-bar-mode)
 (tabbar-local-mode)
 (temp-buffer-resize-mode)
 (text-scale-mode)
 (treemacs-follow-mode)
 (treemacs-git-mode)
 (treemacs-tag-follow-mode)
 (undo-tree-visualizer-selection-mode)
 (unify-8859-on-decoding-mode)
 (unify-8859-on-encoding-mode)
 (url-handler-mode)
 (use-hard-newlines)
 (view-mode)
 (visible-mode)
 (visual-line-mode)
 (window-divider-mode)
 (xref-etags-mode))
greghendershott commented 2 years ago

Thanks for reporting this. Probably the ^M a.k.a. \r is due to Windows using \r\n line endings instead of \n. The buffer contents come from the command-line diff utility.

chansey97 commented 2 years ago

I am using cygwin, so racket-mode maybe call cygwin version of diff.

Where is the diff used in racket-mode source file? Perhaps I could try to add some options or using other diff tools.

Edit: I found it (in racket\commands\macro.rkt), you call racket to do such thing.

chansey97 commented 2 years ago

Adding --strip-trailing-cr to the macro.rkt, the issue can be fixed.

A quick path:

- (system (format "diff -U ~a ~a ~a" -U before-file after-file))
+ (if (eq? (system-type) 'windows)
+     (system (format "diff --strip-trailing-cr -U ~a ~a ~a" -U before-file after-file))
+     (system (format "diff -U ~a ~a ~a" -U before-file after-file)))

I have created a pull request.