Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove language tags and instead utilize code.language #1256

Merged
merged 3 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/vscode/snippets/python_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ctx = Context()
ctx.matches = r"""
app: vscode
tag: user.python
code.language: python
"""
# short name -> ide clip name
ctx.lists["user.snippets"] = {
Expand Down
57 changes: 31 additions & 26 deletions core/modes/language_modes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from talon import Context, Module, actions

ctx = Context()
mod = Module()

# Maps language mode names to the extensions that activate them. Only put things
# here which have a supported language mode; that's why there are so many
# commented out entries. TODO: make this a csv file?
Expand Down Expand Up @@ -59,7 +56,20 @@
"r": ["are language"],
"tex": ["tech", "lay tech", "latex"],
}

mod = Module()

ctx = Context()

ctx_forced = Context()
ctx_forced.matches = r"""
tag: user.code_language_forced
"""


mod.tag("code_language_forced", "This tag is active when a language mode is forced")
mod.list("language_mode", desc="Name of a programming language mode.")

ctx.lists["self.language_mode"] = {
name: language
for language in language_extensions
Expand All @@ -73,41 +83,36 @@
for ext in extensions.split()
}

# Create a context for each defined language
for lang in language_extensions.keys():
mod.tag(lang)
mod.tag(f"{lang}_forced")
c = Context()
# Context is active if language is forced or auto language matches
c.matches = f"""
tag: user.{lang}_forced
tag: user.auto_lang
and code.language: {lang}
"""
c.tags = [f"user.{lang}"]

# Create a mode for the automated language detection. This is active when no lang is forced.
mod.tag("auto_lang")
ctx.tags = ["user.auto_lang"]
forced_language = ""


@ctx.action_class("code")
class code_actions:
class CodeActions:
def language():
result = ""
file_extension = actions.win.file_ext()
if file_extension and file_extension in extension_lang_map:
result = extension_lang_map[file_extension]
return result
return extension_lang_map.get(file_extension, "")


@ctx_forced.action_class("code")
class ForcedCodeActions:
def language():
return forced_language


@mod.action_class
class Actions:
def code_set_language_mode(language: str):
"""Sets the active language mode, and disables extension matching"""
global forced_language
assert language in language_extensions
ctx.tags = [f"user.{language}_forced"]
forced_language = language
# Update tags to force a context refresh. Otherwise `code.language` will not update.
# Necessary to first set an empty list otherwise you can't move from one forced language to another.
ctx.tags = []
ctx.tags = ["user.code_language_forced"]

def code_clear_language_mode():
"""Clears the active language mode, and re-enables code.language: extension matching"""
ctx.tags = ["user.auto_lang"]
global forced_language
forced_language = ""
ctx.tags = []
2 changes: 1 addition & 1 deletion lang/batch/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ctx = Context()
ctx.matches = r"""
tag: user.batch
code.language: batch
"""


Expand Down
2 changes: 1 addition & 1 deletion lang/batch/batch.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.batch
code.language: batch
-
tag(): user.code_comment_line

Expand Down
2 changes: 1 addition & 1 deletion lang/c/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

ctx = Context()
ctx.matches = r"""
tag: user.c
code.language: c
"""

ctx.lists["self.c_pointers"] = {
Expand Down
2 changes: 1 addition & 1 deletion lang/c/c.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.c
code.language: c
-
tag(): user.code_imperative

Expand Down
2 changes: 1 addition & 1 deletion lang/csharp/csharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ctx = Context()
ctx.matches = r"""
tag: user.csharp
code.language: csharp
"""
ctx.lists["user.code_common_function"] = {
"integer": "int.TryParse",
Expand Down
2 changes: 1 addition & 1 deletion lang/csharp/csharp.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.csharp
code.language: csharp
-
tag(): user.code_imperative
tag(): user.code_object_oriented
Expand Down
3 changes: 2 additions & 1 deletion lang/css/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
global_ctx = Context()
ctx = Context()
ctx.matches = """
tag: user.css
code.language: css
code.language: scss
"""

mod.list("css_at_rule", desc="List of CSS @rules")
Expand Down
3 changes: 2 additions & 1 deletion lang/css/css.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tag: user.css
code.language: css
code.language: scss
-
tag(): user.code_comment_block_c_like
tag(): user.code_functions_common
Expand Down
3 changes: 0 additions & 3 deletions lang/css/scss.talon

This file was deleted.

2 changes: 1 addition & 1 deletion lang/go/go.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.go
code.language: go
-
variadic: "..."
logical and: " && "
Expand Down
4 changes: 4 additions & 0 deletions lang/html/html.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
code.language: html
code.language: javascriptreact
code.language: typescriptreact
-
2 changes: 1 addition & 1 deletion lang/java/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ctx = Context()
mod = Module()
ctx.matches = r"""
tag: user.java
code.language: java
"""

# Primitive Types
Expand Down
2 changes: 1 addition & 1 deletion lang/java/java.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.java
code.language: java
-
tag(): user.code_imperative
tag(): user.code_object_oriented
Expand Down
7 changes: 5 additions & 2 deletions lang/javascript/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

mod = Module()
ctx = Context()
ctx.matches = """
tag: user.javascript
ctx.matches = r"""
code.language: javascript
code.language: typescript
code.language: javascriptreact
code.language: typescriptreact
"""

ctx.lists["user.code_common_function"] = {
Expand Down
5 changes: 4 additions & 1 deletion lang/javascript/javascript.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
tag: user.javascript
code.language: javascript
code.language: typescript
code.language: javascriptreact
code.language: typescriptreact
-
tag(): user.code_imperative
tag(): user.code_object_oriented
Expand Down
3 changes: 0 additions & 3 deletions lang/javascript/javascriptreact.talon

This file was deleted.

2 changes: 1 addition & 1 deletion lang/lua/lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod = Module()
ctx = Context()
ctx.matches = r"""
tag: user.lua
code.language: lua
"""

mod.setting(
Expand Down
2 changes: 1 addition & 1 deletion lang/lua/lua.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.lua
code.language: lua
-

tag(): user.code_imperative
Expand Down
4 changes: 4 additions & 0 deletions lang/markdown/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
mod = Module()
ctx = Context()

ctx.matches = r"""
code.language: markdown
"""

mod.list("markdown_code_block_language", desc="Languages for code blocks")
ctx.lists["user.markdown_code_block_language"] = {
"typescript": "typescript",
Expand Down
2 changes: 1 addition & 1 deletion lang/markdown/markdown.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.markdown
code.language: markdown
-
(level | heading | header) one:
edit.line_start()
Expand Down
2 changes: 1 addition & 1 deletion lang/php/php.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ctx = Context()
ctx.matches = r"""
tag: user.php
code.language: php
"""

ctx.lists["user.code_type"] = {
Expand Down
2 changes: 1 addition & 1 deletion lang/php/php.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.php
code.language: php
-
tag(): user.code_imperative
tag(): user.code_object_oriented
Expand Down
2 changes: 1 addition & 1 deletion lang/proto/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

ctx = Context()
ctx.matches = r"""
tag: user.protobuf
code.language: protobuf
"""

ctx.lists["user.code_type"] = {
Expand Down
2 changes: 1 addition & 1 deletion lang/proto/proto.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.protobuf
code.language: protobuf
-

# this is pretty bare-bones, further contributions welcome
Expand Down
2 changes: 1 addition & 1 deletion lang/python/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
mod = Module()
ctx = Context()
ctx.matches = r"""
tag: user.python
code.language: python
"""
ctx.lists["user.code_common_function"] = {
"enumerate": "enumerate",
Expand Down
2 changes: 1 addition & 1 deletion lang/python/python.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.python
code.language: python
-
tag(): user.code_imperative
tag(): user.code_object_oriented
Expand Down
2 changes: 1 addition & 1 deletion lang/r/r.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ctx = Context()

ctx.matches = r"""
tag: user.r
code.language: r
"""

ctx.lists["user.code_common_function"] = {
Expand Down
2 changes: 1 addition & 1 deletion lang/r/r.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.r
code.language: r
-
tag(): user.code_imperative

Expand Down
2 changes: 1 addition & 1 deletion lang/ruby/ruby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ctx = Context()
ctx.matches = r"""
tag: user.ruby
code.language: ruby
"""


Expand Down
2 changes: 1 addition & 1 deletion lang/ruby/ruby.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.ruby
code.language: ruby
-
tag(): user.code_imperative
tag(): user.code_object_oriented
Expand Down
2 changes: 1 addition & 1 deletion lang/rust/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def code_comment_documentation_block_inner():

ctx = Context()
ctx.matches = r"""
tag: user.rust
code.language: rust
"""

scalar_types = {
Expand Down
2 changes: 1 addition & 1 deletion lang/rust/rust.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.rust
code.language: rust
-
tag(): user.code_comment_line
tag(): user.code_comment_block_c_like
Expand Down
2 changes: 1 addition & 1 deletion lang/scala/scala.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ctx = Context()
mod = Module()
ctx.matches = r"""
tag: user.scala
code.language: scala
"""

# Scala Common Types
Expand Down
2 changes: 1 addition & 1 deletion lang/scala/scala.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.scala
code.language: scala
-
tag(): user.code_imperative
tag(): user.code_object_oriented
Expand Down
2 changes: 1 addition & 1 deletion lang/sql/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ctx = Context()
ctx.matches = r"""
tag: user.sql
code.language: sql
"""

# these vary by dialect
Expand Down
2 changes: 1 addition & 1 deletion lang/sql/sql.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.sql
code.language: sql
-
tag(): user.code_operators_math
tag(): user.code_comment_line
Expand Down
2 changes: 1 addition & 1 deletion lang/talon/talon.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
mod.list("talon_modes")

ctx.matches = r"""
tag: user.talon
code.language: talon
"""
ctx.lists["user.code_common_function"] = {
"insert": "insert",
Expand Down
2 changes: 1 addition & 1 deletion lang/talon/talon.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.talon
code.language: talon
-
tag(): user.code_operators_math
tag(): user.code_operators_assignment
Expand Down
2 changes: 1 addition & 1 deletion lang/terraform/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ctx = Context()
mod = Module()
ctx.matches = r"""
tag: user.terraform
code.language: terraform
"""

types = {
Expand Down
2 changes: 1 addition & 1 deletion lang/terraform/terraform.talon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tag: user.terraform
code.language: terraform
-
tag(): user.code_comment_block_c_like
tag(): user.code_comment_line
Expand Down
Loading