pmatos / racket-news

Repository for the Racket News Website
https://racket-news.com
11 stars 2 forks source link

Rename Identifier as a Quickscript #72

Closed spdegabrielle closed 2 years ago

spdegabrielle commented 2 years ago

@metaxal — Rename Identifier is now available as a quickscript:

#lang racket/base

(require quickscript
         racket/class
         racket/gui/base
         string-constants)

;;; License: [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) or
;;;          [MIT license](http://opensource.org/licenses/MIT) at your option.

(script-help-string "Rename the identifier under the cursor (if check syntax succeeded)")

(define-script rename-identifier
  #:label "Rename &Identifier"
  #:menu-path ("Re&factor")
  (λ (selection #:definitions defs)
    (define kmap (send defs get-keymap))
    ;; The last `#true` argument ensures that all keymaps in the chain are tried.
    (send kmap call-function (string-constant cs-rename-id) defs (new event%) #true)))

(module url2script-info racket/base
  (provide filename url)
  (define filename "rename-identifier.rkt")
  (define url "https://gist.github.com/Metaxal/a9dc34faaff4ec7e3c7872b63cc1b76f"))

https://gist.github.com/Metaxal/a9dc34faaff4ec7e3c7872b63cc1b76f

This is useful if you have checked "Enable keybindings in menus" and you want to call "Rename identifier" via a keyboard shortcut (to customize in the quickscript), or via "Alt-s, f, i" (navigate the menus with the keyboard).