This project inspired by a similar package for vs-code - turbo-console-log, and provides functionality for fast log message inserting under current line. It works for js-mode, typescript-mode, go-mode and python.
(use-packa)
(use-package turbo-log
:quelpa (turbo-log :fetcher github :repo "artawower/turbo-log.el")
:bind (("C-s-l" . turbo-log-print)
("C-s-i" . turbo-log-print-immediately)
("C-s-h" . turbo-log-comment-all-logs)
("C-s-s" . turbo-log-uncomment-all-logs)
("C-s-[" . turbo-log-paste-as-logger)
("C-s-]" . turbo-log-paste-as-logger-immediately)
("C-s-d" . turbo-log-delete-all-logs))
:config
(setq turbo-log-msg-format-template "\"🚀: %s\"")
(setq turbo-log-allow-insert-without-treesit-p t))
;; packages.el
(package! turbo-log :recipe (:host github :repo "artawower/turbo-log"))
;; config.el
(use-package turbo-log
:bind (("C-s-l" . turbo-log-print)
("C-s-i" . turbo-log-print-immediately)
("C-s-h" . turbo-log-comment-all-logs)
("C-s-s" . turbo-log-uncomment-all-logs)
("C-s-[" . turbo-log-paste-as-logger)
("C-s-]" . turbo-log-paste-as-logger-immediately)
("C-s-x" . turbo-log-delete-all-logs))
:config
(setq turbo-log-msg-format-template "\"🚀: %s\"")
(setq turbo-log-allow-insert-without-treesit-p t))
Clone the repo to a directory, say ./emacs.d/lisp
with
git clone https://github.com/chookity-pokk/turbo-log.git
Then put this in your init to load the package
(add-to-list 'load-path "~/.emacs.d/lisp/turbo-log")
(require 'turbo-log)
(use-package turbo-log
:bind (("C-s-l" . turbo-log-print)
("C-s-i" . turbo-log-print-immediately)
("C-s-h" . turbo-log-comment-all-logs)
("C-s-s" . turbo-log-uncomment-all-logs)
("C-s-[" . turbo-log-paste-as-logger)
("C-s-]" . turbo-log-paste-as-logger-immediately)
("C-s-d" . turbo-log-delete-all-logs))
:config
(setq turbo-log-msg-format-template "\"🚀: %s\"")
(setq turbo-log-allow-insert-without-treesit-p t))
emacs versions below 29 are no longer supported, but you can still use an older version:
(use-package turbo-log
:defer t
:ensure (turbo-log :type git :host github :repo "Artawower/turbo-log.el" :branch "tree-sitter"))
turbo-log-msg-format-template
- template for entire part inside logger
turbo-log-payload-format-template
- template for payload part (selected region or implicite extracted identifier)
turbo-log-line-number-format-template
- optional template for formatting line number, when not provided, the line number will not be inserted
turbo-log-buffer-name-format-template
- template for file name inserting
turbo-log-argument-divider
- divider for arguments (in most case it’s a comma)
turbo-log-allow-insert-without-treesit-p
- allow to insert logs without treesit (in such case logger will be inserted next line only, also its a necessary for modes without treesit support)
turbo-log-loggers
- its a most interesting part of your config. You can use every settings as plist for specific logger (without turbo-log
prefix), for example:
(turbo-log-configure
:modes (typescript-mode js2-mode web-mode)
:strategy merge
:loggers ("console.log(%s)" "console.debug(%s)" "console.warn(%s)")
:jump-list ((class_declaration (method_definition "constructor")))
:identifier-node-types (identifier member_expression)
:post-insert-hook (prettier-prettify)
:msg-format-template "'🦄: %s'")
Where:
modes
- list of modes which have to be updated
strategy
- update strategy, merge
will update existing plist (only first level of nested structure), replace
will override all mode settings
loggers
- list of available loggers, when there are more then 1 turbo-log-print
will ask to choose logger.
jump-list
- internal command for insert current logger to specific line number by determined node type. Its a alist that consist of cons where car is node type and cdr is a alist of inserting position and optional name of foud node type, after which logger will be inserted.
identifier-node-types
- optional alist of node types for extracting identifiers
post-insert-hook
- list of hooks that will be triggered after logger inserted. Its a good place to call format-all-buffer
or prettier-prettify
methods.
- [X] Python
- [X] Golang
- [X] Javascript
- [X] Typescript
- [X] Java
- [X] C#
- [X] Rust
- [X] Ruby
- [-] Lua (Without treesit)
- [-] Elisp (Without treesit)
- [ ] C++
Any contribution is greatly appreciated!
Run eldev test
, checkdoc
and package-lint-current-buffer
(from package-lint ) before creating the pull request
eldev prepare && eldev -p -dtT -C test