Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shsms/mime
mime is a scripting tool for text processing, inspired by Emacs Keyboard Macros.
https://github.com/shsms/mime
cpp emacs scripting text-processing
Last synced: 4 months ago
JSON representation
mime is a scripting tool for text processing, inspired by Emacs Keyboard Macros.
- Host: GitHub
- URL: https://github.com/shsms/mime
- Owner: shsms
- License: gpl-3.0
- Created: 2020-10-23T18:29:27.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-27T11:37:21.000Z (over 1 year ago)
- Last Synced: 2024-09-29T18:01:27.000Z (5 months ago)
- Topics: cpp, emacs, scripting, text-processing
- Language: C++
- Homepage: https://shsms.github.io/mime
- Size: 1.54 MB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
#+startup: indent
* mime[[https://github.com/shsms/mime/actions][https://github.com/shsms/mime/workflows/build/badge.svg]] [[https://codecov.io/gh/shsms/mime][https://codecov.io/gh/shsms/mime/branch/main/graph/badge.svg?token=ASAIA6P309]]
Mime is a scripting tool for text processing, inspired by Emacs.
Mime provides an editor-like abstraction for manipulating text files,
but in a scripting environment, without an editor. This enables very
sophisticated transformations that are easy to do through tools
like Emacs Keyboard Macros, but hard to do in code.- *Documentation*: https://shsms.github.io/mime
** Dependencies
For providing its functionalities, Mime depends on these amazing
libraries:- [[https://github.com/ChaiScript/ChaiScript][ChaiScript]] for the scripting language.
- [[https://github.com/arximboldi/immer][Immer]] for data representation.
- [[https://github.com/jarro2783/cxxopts][cxxopts]] for parsing of cli arguments.
- [[https://github.com/google/googletest][googletest]] for unit tests.(You don't have to install them separately, they are added as
submodules to this repository, so just following the build steps in
the [[https://mime.dev/getting-started.html][Getting started]] page is enough.)** An example mime script
#+begin_src js
var b = buffer("main.go");
var doc_c = b.new_cursor();
var nav_c = b.new_cursor();b.use_cursor(nav_c);
while(b.find("func ") >= 0) {
b.set_mark();
b.find("(");
b.backward();var fname = b.copy();
b.use_cursor(doc_c);
b.paste("// FuncAlert: " + fname + "\n");b.use_cursor(nav_c);
}
b.use_cursor(doc_c);
b.paste("\n");b.save_as("mimeout.go");
#+end_srcIf there is a file "main.go" in the same directory with the below
contents,#+begin_src go
package mainimport "fmt"
func main() {
fmt.Print(hello(), world())
}func world() string {
return "world!"
}func hello() string {
return "Hello "
}
#+end_srcThen running the above mime script with:
#+begin_src shell
mime gofunc.mime
#+end_srcwould generate a new file "mimeout.go" with below contents:
#+begin_src go
// FuncAlert: main
// FuncAlert: world
// FuncAlert: hellopackage main
import "fmt"
func main() {
fmt.Print(hello(), world())
}func world() string {
return "world!"
}func hello() string {
return "Hello "
}
#+end_srcHere's what the script does:
1. open file "main.go"
2. create two cursors - one for adding documentation at the top,
and one for navigating the file.
3. switch to the navigation cursor.
4. find and goto next occurence of the string "func ". If found:
1. set mark (emacs parlance for "start selecting")
2. find next occurence of "(" (assuming we are operating on a
valid go program, we don't check if "(" was found, we assume
it is there.)
3. go back one character, we don't want to copy the "("
4. copy the text between mark (where we started selecting in
4.1), and (current cursor) point, and store in a var called
"fname".
5. switch to the documentation cursor, which is still at the top
6. paste the function name in "fname" with a comment prefix and
a newline at the end.
7. switch to navigation cursor
8. goto step 4.
5. switch to doc cursor to insert a final newline to introduce a
gap between inserted text and original program.
6. save file under a new name.** Projects using mime
- *ulysses-annotated*: a project to automatically generate an annotated ebook version of [[https://en.wikipedia.org/wiki/Ulysses_(novel)][Ulysses]]. Read more in its [[https://github.com/shsms/ulysses-annotated][github page]] or on [[http://www.joyceproject.com/pages/ebook.htm][joyceproject.com]]
** Contributing
If you'd like to contribute a feature or a bug fix, feel free to send a pull request!