Code Monkey home page Code Monkey logo

hx-comm's Introduction

hx-comm

This tool allows you to work with comments when editing code in Helix editor. The main differences from the commenting in Helix (via the keyboard shortcut Ctrl-C):

  • the ability to configure the necessary identifiers of comments (for example, when editing a file with a C extension, you can use // or /* .. */);
  • if you lack support for HTML and CSS commenting, so you can do it with this utility.

How it works

Helix allows you to call an external app and pass selected text as input and insert the output of this app back through the use of the :pipe <external app>. And hx-comm uses this ability.

This utility also uses 2 files as command line parameters:

  1. The first file comm-lang contains the extension of the file being edited in Helix. The contents of this file do not need to be changed manually, the bash script hx-comm-lang was created for this purpose.
  2. The second file comm-lang-table contains mappings of comment identifiers for different file extensions. You can edit it yourself by adding the file extensions you need and the start and end identifiers of comments associated with them. Be careful that if you do not use the end comment identifier, there must be a newline character immediately after the start identifier. The * must be on the last line and it indicates the use of following comment identifiers for any other extensions.

Dependencies

The following packages must be installed on your system:

  1. C compiler (clang or gcc). I have only used and tested with Clang.
  2. inotify-tools
  3. sed
  4. git

inotify-tools and sed needs to run hx-comm-lang bash script.

Installation

  1. Clone this repo:
git clone https://github.com/b52es/hx-comm.git
  1. Change dir:
cd hx-comm
  1. Compile:
clang hx-comm-edit.c -o hx-comm-edit
  1. Make it executable:
chmod +x hx-comm-edit; chmod +x hx-comm-lang
  1. Set environment variable (for bash):
echo "export HX_COMM_DIR=${PWD}" >> $HOME/.bashrc

if you are using another shell then you should change the above command accordingly.

  1. Open and edit your Helix config.toml by adding following lines in section [keys.normal]:
# "#" - used to comment out the entire line
"#" = ["extend_to_line_bounds", ":pipe ${HX_COMM_DIR}/hx-comm-edit ${HX_COMM_DIR}/comm-lang ${HX_COMM_DIR}/comm-lang-table"]
# "$" - used to comment out a single line from the current cursor position to the end of the line
"$" = ["select_mode", "goto_line_end_newline", "normal_mode", ":pipe ${HX_COMM_DIR}/hx-comm-edit ${HX_COMM_DIR}/comm-lang ${HX_COMM_DIR}/comm-lang-table"]
# "^" runs the hx-comm-lang script, after which you need to save the current file via ":w"
"^" = ":sh ${HX_COMM_DIR}/hx-comm-lang"

You can select another keyboard shortcuts, see Helix key remapping docs.

  1. Log out and log in to your Linux machine.

Usage

  1. Open some code file in Helix.
  2. Press key ^ and then save the file by typing :w. This is how the bash script hx-comm-lang will work and write the extension of the opened file to the comm-lang file.
  3. Select some lines of code using x key.
  4. Press # or $ to comment them out.
  5. Press # or $ again to uncomment them back.

PS. # and $ works the same when multiple lines are selected. Their main difference appears when nothing is selected:

  • # - selects the entire current line;
  • $ - selects the line from the current cursor position to the end of the current line.

hx-comm's People

Contributors

b52es avatar

Stargazers

 avatar

Watchers

 avatar

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.