Skip to content

feat(edit_src): Add org_edit_src_filetype_map for custom src block filetypes. #1002

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions docs/configuration.org
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,16 @@ The indent value for content within =SRC= block types beyond the
existing indent of the block itself. Only applied when exiting from an
=org_edit_special= action on a =SRC= block.

*** org_edit_src_filetype_map
:PROPERTIES:
:CUSTOM_ID: org_edit_src_filetype_map
:END:
- Type: =table<string, string>=
- Default: ={}=
This filetype map associates the language name from an Org source block
with the corresponding Vim filetype, which is then applied to the temporary
buffer.

*** org_custom_exports
:PROPERTIES:
:CUSTOM_ID: org_custom_exports
Expand Down
1 change: 1 addition & 0 deletions lua/orgmode/config/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ local DefaultConfig = {
},
org_src_window_setup = 'top 16new',
org_edit_src_content_indentation = 0,
org_edit_src_filetype_map = {},
org_id_uuid_program = 'uuidgen',
org_id_ts_format = '%Y%m%d%H%M%S',
org_id_method = 'uuid',
Expand Down
2 changes: 2 additions & 0 deletions lua/orgmode/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ end
---@param skip_ftmatch? boolean
---@return string
function utils.detect_filetype(name, skip_ftmatch)
local config = require('orgmode.config')
local map = {
['emacs-lisp'] = 'lisp',
elisp = 'lisp',
Expand All @@ -576,6 +577,7 @@ function utils.detect_filetype(name, skip_ftmatch)
shell = 'bash',
uxn = 'uxntal',
}
map = vim.tbl_deep_extend('force', map, config.org_edit_src_filetype_map)
if not skip_ftmatch then
local filename = '__org__detect_filetype__.' .. (map[name] or name)
local ft = vim.filetype.match({ filename = filename })
Expand Down