GithubHelp home page GithubHelp logo

greghendershott / racket-mode Goto Github PK

View Code? Open in Web Editor NEW
677.0 30.0 90.0 4.11 MB

Emacs major and minor modes for Racket: edit, REPL, check-syntax, debug, profile, and more.

Home Page: https://www.racket-mode.com/

License: GNU General Public License v3.0

Racket 44.87% Emacs Lisp 43.84% Makefile 0.20% Scheme 11.09%
racket emacs racket-mode emacs-lisp gnu-emacs drracket

racket-mode's Introduction

Racket mode for GNU Emacs

https://github.com/greghendershott/racket-mode/workflows/CI/badge.svg https://melpa.org/packages/racket-mode-badge.svg https://elpa.nongnu.org/nongnu/racket-mode.svg https://img.shields.io/badge/Docs-Documentation-blue.svg

A variety of Emacs major and minor modes for Racket: edit, REPL, check-syntax, debug, profile, logging, and more. The edit/run experience is similar to DrRacket.

Compatible with Emacs 25.1+ and Racket 6.12+.

Documentation

See the Guide and Reference.

Contributing

Pull requests are welcome; please see CONTRIBUTING.org.

Acknowledgments

THANKS.org.

Alternatives

  • Emacs’ built-in `scheme-mode` major mode plus the minor modes Quack and/or Geiser.

racket-mode's People

Contributors

3rdlaw avatar capfredf avatar cybersyn-io avatar david-christiansen avatar dpercy avatar florence avatar greghendershott avatar hencq avatar hkrish avatar iitalics avatar mswift42 avatar noahstorym avatar nverno avatar odanoburu avatar pmatos avatar purcell avatar rcherrueau avatar samth avatar scolobb avatar sorawee avatar syohex avatar tgbugs avatar tonyg avatar utkarsh181 avatar vkz avatar willghatch avatar xuchunyang avatar yasuyk avatar yilinwei avatar zenspider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

racket-mode's Issues

Company backend

I know this may be a lot to ask but it would be really nice if this package had a backend for company-mode so that it would do completion. I find completion to be help full in languages like racket and clojure where the number of functions in a given namespce can be overwhelming and one tends to forget what is at arms length.

Display `lambda` as `λ` outside parens, too?

On #racket IRC:

<atomx> in racket mode , if I know the word 'lambda, how can I tell emacs to display the greek letter ?
<atomx> it displays it only inside a list

My answer is too long for IRC, plus I want to doc it here:

  1. Frankly, I inherited this code to display lambda as λ from Quack mode (which I used for a long time before writing racket-mode). It never occurred to me for it to work differently.
  2. I could look at changing this. However, I'm not sure displaying lambda as λ outside list forms would be desirable in all cases?
  3. Now that I stop and think about it, does the feature -- as it exists now -- even make sense for racket-mode, at all?? After all:
    • Racket handles Uniode and λ is a valid identifier.
    • You can C-M-y to insert λ.

As a result, maybe the right thing to do here is remove this feature, not expand it. Or at least, make it optional and disable it by default -- i.e. deprecate it, but whoever still wants it can enable it.

Limit error context ("stack trace") items

With an error in something like a parser combinator, the context ("stack trace") can be extremely long.

Should probably just limit the context to (say) 10 items.

Edit wxme format racket files

This might be a big ask but what would be needed to extend racket-mode to parse and write DrRacket files in WXME format? It would be a huge win to be able to edit racket files which contain images in emacs.

Consider `scheme-indent-function` settings?

People who have used scheme-mode to edit Racket code, prior to using racket-mode, may have accumulated a number of (put 'some-function 'scheme-indent-function N) settings in their emacs.d.

I think nearly all of those are Racket-specific things that I've added -- or ought to add, if I overlooked any -- to racket-mode itself.

Having said that, maybe it would be useful and non-harmful to have racket-mode do:

(or (get (intern-soft function) 'racket-indent-function)
    (get (intern-soft function) 'scheme-indent-function)

i.e. Utilize any scheme-indent-function properties that don't exist for racket-indent-function.

Maybe??

Current vs. load directory

From @bremner via #racket IRC and Debian paste:

  1. open the following racket program
#lang racket
(file->string "foo.rkt")
  1. open a file in different directory

  2. go back to buffer 1 and M-x run-racket (or F5, or...)

  3. kill that repl, repeat step 3.

For me, racket is then running in the second directory and hence the program fails.

rainbow-delimiters

@florence reported that racket-mode's font-lock of parens prevents rainbow-delimiters from doing its thing. Presumably rainbow-delimiters won't font-lock something that's already font-locked to other than default?

Best resolution might be to automatically detect if rainbow-delimiters is active.

Next-best resolution would be to add a customization option. (There's already an option to choose the paren font-lock attributes. The new option would be whether to font-lock them, at all.)

cf #6

racket-visit-definition always stops at the top of typed/racket modules

I would guess this has something to do with how typed/racket expands provides for regular racket interaction.

A quick scan of an expanded typed/racket file shows how typed/racket does this:

(define-syntaxes:401 (request:402)
(let-values:403 (((c:404) (quote-syntax:405 request:397)))
(if:404 (#%app:406 unbox:404 typed-context?:404)
(#%app:407 renamer:404 (quote-syntax:408 request) c:404)
(#%app:409 renamer:404 c:404))))
(#%provide:410 request:402)

The 'request' function is being wrapped by an non-original (in the sense of syntax-original?) identifier, which when inspected is not original and has the srcloc of the provided identifier, not the defined one. Now why racket-mode isn't jumping to that identifier is beyond me. A quick scan of how find-definition and define-in-stx works makes me think it should.

#:keyword font-lock bug

In something like this:

(struct
 s
 (a b)
 #:transparent)

(define ...

The red #:keyword font is incorrectly applied past #:transparent to the closing ) of the struct form and even into the (define. A space before #:transparent and ) avoids this, so, probably the regexp just needs to be tweaked to stop on space. There's always a trailing space when #:keywords are used as function arguments, but, need to handle this case, too.

Problems with filenames containing spaces

Need to use shell-quote-argument in some places. But also, problems yet again with comint-prompt-regexp; probably need to change strategy with the prompt character, e.g. instead of > use .

REPL fails to load

after setting the racket program and reco program in my config by hand when I try to run the repl I get the following error.

here is how I have racket mode configure on my system
https://github.com/gozes/.emacs.d/blob/master/gozes/init-racket.el

/home/gozes/.emacs.d/elpa/racket-mode-20140509.643/sandbox.rkt:30:3: current-directory-for-user: unbound identifier in module
in: current-directory-for-user
context...:
standard-module-name-resolver

Process Racket REPL exited abnormally with code 1

Racket REPL shows up in two windows

Reported via bremner on #racket IRC:

I notice that f5 splits my window horizontally and then replaces both halve with the repl. I guess it must be something specific to my setup...

I can reproduce as follows. Start emacs -Q, evaluate http://paste.debian.net/75364/ ; then in a different shell run "emacsclient -c". In the new emacs frame, edit a racket file and hit f5.

http://paste.debian.net/75364/ is:

(add-to-list 'load-path (expand-file-name "~/.emacs.d/el-get/racket-mode"))
(server-start)
(require 'racket-mode)

help is broken for default racket-program

(shell-command (concat (expand-file-name
                              "raco"
                              (file-name-directory racket-program))
                             " doc "
                             (shell-quote-argument (format "%s" sym))))

when racket-program is defaulting to "racket", file-name-directory results in nil, which then expands to default-directory instead of letting it just use $PATH.

Ellipses throw off indentation

For example in a match form like this:

(define-syntax (fstruct stx)
  (syntax-parse stx
    [(_ id:id (field:id ...))
     (with-syntax ([(accessor ...)
                    (for/list ([fld (in-list (syntax->list #'(field ...)))])
                      (format-id stx "~a-~a" (syntax->datum #'id) fld))])
       #'(serializable-struct
          id (field ...) #:transparent
          #:property prop:procedure
          (lambda (self . args)
            (match args
              [(list 'field) (accessor self)] ...
              [(list (list 'field)) (accessor self)] ...
              [(list (list-rest 'field fields)) ((accessor self) fields)] ...
              [(list-rest 'field f args)
               (struct-copy id self
                            [field (apply f (accessor self) args)])] ...
                            [(list-rest (list 'field) f args)  ;<-- THIS SEXPR IS INDENTED TOO FAR
                             (struct-copy id self
                                          [field (apply f (accessor self) args)])] ...
                                          [(list-rest (list-rest 'field fields) args)
                                           (struct-copy id self
                                                        [field (apply (accessor self) fields args)])] ...))))]))

Whereas DrRacket does handle this example correctly.
reported by @technomancy on #racket

company-mode enabled even when global-company-mode is disabled

I am noticing company-mode being enabled for racket-mode buffers when I don't expect it to be.

What I think is happening: If global-company-mode has ever ever been enabled during a given Emacs session, then even after it is disabled, racket-mode buffers will open with company-mode on.

Maybe we need to add something like:

(defcustom racket-use-company-mode t
  "Enable company-mode for racket-mode edit buffers?"
  :tag "Use company-mode?"
  :type 'boolean
  :group 'racket
  :safe 'booleanp)

Unicode prime mark is not treated as part of an identifier

When using paredit with racket-mode, M-r strips trailing unicode prime marks.

I thought this was a paredit bug, but it works in other lisp modes. With the point at the ^, performing paredit raise behaves differently:

(hello ^world′) -> world ; -> in racket-mode
(hello ^world′) -> world′ ; -> in emacs-lisp-mode

racket-repl.el gives error about (car x)

When I try to install racket-mode on emacs 23, emacs gives the following error:

Leaving directory `/home/sjors/.emacs.d/elpa/racket-mode-20141023.637'

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-common.el at Mon Nov  3 13:22:01 2014
Entering directory `/home/sjors/.emacs.d/elpa/racket-mode-20141023.637/'

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-complete.el at Mon Nov  3 13:22:02 2014
racket-complete.el:19:1:Error: Wrong type argument: integer-or-marker-p, (car x)

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-edit.el at Mon Nov  3 13:22:02 2014
racket-edit.el:22:1:Error: Wrong type argument: integer-or-marker-p, (car x)

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-emacs-compat.el at Mon Nov  3 13:22:02 2014

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-eval.el at Mon Nov  3 13:22:02 2014
racket-eval.el:19:1:Error: Wrong type argument: integer-or-marker-p, (car x)

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-font-lock.el at Mon Nov  3 13:22:02 2014

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-indent.el at Mon Nov  3 13:22:02 2014

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-keywords-and-builtins.el at Mon Nov  3 13:22:02 2014

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-mode.el at Mon Nov  3 13:22:02 2014
racket-mode.el:46:1:Error: Wrong type argument: integer-or-marker-p, (car x)

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-repl.el at Mon Nov  3 13:22:02 2014
racket-repl.el:35:20:Error: Wrong type argument: integer-or-marker-p, (car x)

Compiling file /home/sjors/.emacs.d/elpa/racket-mode-20141023.637/racket-tests.el at Mon Nov  3 13:22:02 2014
racket-tests.el:1:1:Error: Wrong type argument: integer-or-marker-p, (car x)

It seems that in racket-repl.el, line 36, the lambda is given a cons cell with a wrong type of car.
The error doesn't show in emacs 24 (gone through a dependency minefield on Debian Wheezy to get it installed), though Run generates an error with that version (will make a seperate issue of that).

racket-base-requires not adding a require for-syntax of racket/base

Given:

#lang racket
(begin-for-syntax 1) 

Do M-x racket-base-requires.

Actual result:

#lang racket/base
(begin-for-syntax 1) 

Expected result:

#lang racket/base
(require (for-syntax racket/base))
(begin-for-syntax 1) 

On #racket irc @samth points out that it works at the level of macro-debugger/analysis/check-requires

    [samth@huor:~/tmp plt] r
    Welcome to Racket v6.1.1.4.
    -> (require macro-debugger/analysis/check-requires)
    -> (check-requires "mod.rkt")
    BYPASS racket at 0
    TO racket/base at 0
    TO racket/base at 1
    ->
    [samth@huor:~/tmp plt] cat mod.rkt
    #lang racket
    (begin-for-syntax 1)

graphics don't clear when using erase-buffer

Any graphics output into the repl stay when you invoke erase-buffer. I don't know if that is erase-buffer's fault or racket-mode, but I thought you should have a record of it.

Display images in REPL

At RacketCon a couple people pointed out it would be nice if racket-mode could display images in the REPL.

Well, at least to display #<image>s read-only (as does Geiser).

But probably not live/interactive (as does DrRacket, as Neil Toronto used in his 3D demo, to click and rotate the 3D images).

Indent for/fold

Default indentation of for/fold in Scheme mode is:

(for/fold ([x 0])
    ([y 1])
  ...)

Instead make it:

(for/fold ([x 0])
          ([y 1])
  ...)

Do this for all off

  1. for/fold
  2. for*/fold
  3. for/fold:
  4. for*fold:
  5. User-defined for/XXX and for*/XXX forms.

Executive decision: Don't bother with the differently shaped forms for/fold/derived and for*/fold/derived --- they're used infrequently by macro implementers to implement new for/XXX and for*/XXX.

Support programs that import `racket/gui/base`

If a program requires 'racket/gui/base' `racket-run' will fail if used multiple times, with the error:

 ; cannot instantiate `racket/gui/base' a second time in the same process

Sometimes this even happens:

 ; cannot instantiate `racket/gui/base' a second time in the same process

> 
Process Racket REPL segmentation fault: 11

Although I can't quite nail down whats causing the segfault. It seems to only happen with (require redex).

Typed Racket: Type info lost for `require`d function

For example, given these two files:

;; tr0.rkt
#lang typed/racket/base
(: f (Number -> Number))
(define (f n)
  n)
(provide f)
;; tr1.rkt
#lang typed/racket/base
(require "tr0.rkt")
(f 1)

Then:

$ racket
Welcome to Racket v6.0.1.4.
-> (require xrepl)  ;maybe already in .racketrc
-> ,en tr0.rkt
"tr0.rkt"> (f 1)
- : Number
1
"tr0.rkt"> ,en tr1.rkt
1
"tr1.rkt"> (f 1)
; readline-input:4:0: Type Checker: missing type for identifier;
;  consider using `require/typed' to import it
;   identifier: idY6
;   from module: tr0.rkt
;   in: (f 1)
; [,bt for context]
"tr1.rkt">

In other words:

On enter! to tr0.rkt, where f is defined:

  • f evaluates fine in the REPL.

On enter! to tr1.rkt, where f is required:

  • f evaluates fine in the tr1.rkt source file
  • f seems to lack type information, in the REPL.
    (Same problem in racket-mode REPL.)

However in the DrRacket REPL ("interactions" pane), f evaluates just fine!

Indent of `for` forms should handle optional type annotation

The for/XXX forms have an optional type annotation -- the type-ann-maybe in:

(for/list type-ann-maybe (for-clause ...) expr ...+)

We'd like this to indent as e.g.:

(for/list: : (Listof T)
           ([x xs])
  x)

But currently it's:

(for/list: : (Listof T)
           ([x xs])
           x)

i.e. When the : ann is present, should act like indent of 3 not 1.

single `;` comment indentation

This is nitpicking but do you know why indenting a single ; jumps to column 41? (two or more ; chars indents properly) Not a bug in racket-mode since I think it's from scheme-mode but I never figured out why it does this.

Stop error context ("stack trace") at "system" modules

The context down into "system" modules -- like racket/sandbox, racket/contract/private/blame, and racket/private/more-scheme -- is usually just noise.

Ideally this list would be defcustom instead of hard-coded. However, it's something that our sandbox.rkt needs to do using define-runtime-path, so at the moment I don't see how that would be possible.

Trouble with /usr/share/racket/collects/racket/format.rkt

When I try to execute any file while in racket-mode with , emacs returns an error:

"""

default-load-handler: cannot open input file: "/usr/share/racket/collects/racket/format.rkt" (No such file or directory; errno=2)

=== context ===
standard-module-name-resolver
standard-module-name-resolver
standard-module-name-resolver

Process Racket REPL exited abnormally with code 1

"""

Since the error is about a file not existing, I thought I might solve it with a simple
sudo touch /usr/share/racket/collects/racket/format.rkt
which, as you probably know, creates an empty file, but emacs then returns:

"""

default-load-handler: expected a module' declaration forformat', but found end-of-file in: #path:/usr/share/racket/collects/racket/format.rkt

=== context ===
standard-module-name-resolver
standard-module-name-resolver
standard-module-name-resolver

Process Racket REPL exited abnormally with code 1

"""

I use emacs 24 (alongside emacs 23) on Debian Wheezy and installed racket-mode via MELPA, I think (though racket-mode's files are under ~/.emacs.d/elpa).
It was quite a dependency minefield to get emacs 24 installed on Wheezy via the repositories (had to manually install several libs from the wheezy-backport), so I'm not quite sure whether everything was installed as it should.

visit definition with a contract

If i try to find a symbol witch avec been provided with a contract (throught the provide form), it didn't find the position of the definition in the file, just the file.

I think this could be achieved by using nominal-source-id from identifier-binding, and search for a (define-values (nominal-source-id) form with positional information.

Offer to help with bytecode mismatches?

When working on a project that's been compiled -- that has compiled subdir(s) created by raco make or raco setup -- eventually you can get this error:

link: module mismatch; possibly, bytecode file needs re-compile because dependencies changed

The solution is to rm -rf compiled/ or re-run raco make or raco setup. Which isn't difficult to do. But it's kind of a buzz-kill flow-breaker to need to M-x shell, cd to the right directory, issue the rm or raco command... then remember what you were focused on before this annoying distraction.

Could racket-mode notice this sort of error, and do something automatically? Maybe after a y/n prompt?

type printed twice in repl

After running on a trivial typed/racket file e.g.

#lang typed/racket
1

entering anything in the repl prints out the type twice.

foo.rkt> 1
- : Integer [generalized from One]
- : Integer [generalized from One]
1

Indent {} for #lang rackjure

Currently we use scheme-mode's default indentation for a plain list -- whether using (), {}, or [].

As a result, {'a 1 'b 2 'c 3} indents as:

{'a 1
    'b 2
    'c 3}

but we want:

{'a 1
 'b 2
 'c 3}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.