Skip to content

Instantly share code, notes, and snippets.

@Metaxal
Last active May 20, 2021 15:03
Show Gist options
  • Save Metaxal/971e7a4d3098ac45930381beb02f8892 to your computer and use it in GitHub Desktop.
Save Metaxal/971e7a4d3098ac45930381beb02f8892 to your computer and use it in GitHub Desktop.
quickscript to remove trailing spaces in the whole file
#lang racket/base
;;; 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.
(require quickscript
racket/class
racket/string)
(script-help-string "Remove trailing spaces in the current tab")
(define-script remove-trailing-spaces
#:label "Remove trailing spaces"
(λ (selection #:editor ed)
(send ed begin-edit-sequence)
(define str (send ed get-text))
(define new-str
(string-join
(map (λ (line) (string-trim line #:left? #f))
(string-split str "\n"))
"\n"))
(send ed erase)
(send ed insert new-str)
(send ed end-edit-sequence)
#f))
(module url2script-info racket/base
(provide filename url)
(define filename "remove-trailing-spaces.rkt")
(define url "https://gist.github.com/Metaxal/971e7a4d3098ac45930381beb02f8892"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment