-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
Support sheband and tangle mode header tag #939
base: master
Are you sure you want to change the base?
Changes from all commits
f0ca9b7
ef7e508
d27db58
556578d
a2a3ef8
52b345d
0a45dc0
f91330e
160fe5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,12 @@ function Tangle:tangle() | |
|
||
for _, info in ipairs(valid_blocks) do | ||
if tangle_info[info.filename] then | ||
table.insert(tangle_info[info.filename], '') | ||
table.insert(tangle_info[info.filename]['content'], '') | ||
else | ||
tangle_info[info.filename] = {} | ||
tangle_info[info.filename] = { content = {} } | ||
end | ||
|
||
local filemode = tangle_info[info.filename]['mode'] | ||
local do_noweb = info.header_args[':noweb'] == 'yes' or info.header_args[':noweb'] == 'tangle' | ||
local parsed_content = info.content | ||
|
||
|
@@ -60,15 +61,51 @@ function Tangle:tangle() | |
vim.fn.mkdir(path, 'p') | ||
end | ||
|
||
local shebang = info.header_args[':shebang'] | ||
if shebang then | ||
shebang = shebang:gsub('[\'"]', '') | ||
table.insert(parsed_content, 1, shebang) | ||
if filemode == nil then | ||
filemode = 'o755' | ||
end | ||
end | ||
|
||
local tangle_mode = info.header_args[':tangle-mode'] | ||
if tangle_mode then | ||
filemode = tangle_mode:gsub('[\'"]', '') | ||
end | ||
|
||
if info.header_args[':mkdirp'] == 'yes' then | ||
local path = vim.fn.fnamemodify(info.filename, ':h') | ||
vim.fn.mkdir(path, 'p') | ||
end | ||
|
||
local shebang = info.header_args[':shebang'] | ||
if shebang then | ||
shebang = shebang:gsub('[\'"]', '') | ||
table.insert(parsed_content, 1, shebang) | ||
end | ||
Comment on lines
+83
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is already done above on line 64. Is there a reason why it's needed twice? |
||
|
||
if info.name then | ||
block_content_by_name[info.name] = parsed_content | ||
end | ||
vim.list_extend(tangle_info[info.filename], parsed_content) | ||
vim.list_extend(tangle_info[info.filename]['content'], parsed_content) | ||
tangle_info[info.filename]['mode'] = filemode | ||
end | ||
|
||
local promises = {} | ||
for filename, content in pairs(tangle_info) do | ||
table.insert(promises, utils.writefile(filename, table.concat(self:_remove_obsolete_indent(content), '\n'))) | ||
for filename, block in pairs(tangle_info) do | ||
table.insert( | ||
promises, | ||
utils.writefile(filename, table.concat(self:_remove_obsolete_indent(block['content']), '\n')) | ||
) | ||
|
||
local mode_str = block['mode'] | ||
if mode_str and mode_str:sub(1, 1) == 'o' then | ||
mode_str = mode_str:sub(2) | ||
local mode_num = tonumber(mode_str, 8) | ||
vim.loop.fs_chmod(filename, mode_num) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sound good, I'm make the changes |
||
end | ||
end | ||
Promise.all(promises):wait() | ||
utils.echo_info(('Tangled %d blocks from %s'):format(#valid_blocks, vim.fn.fnamemodify(self.file.filename, ':t'))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
tangle-mode
also apply to directories? I can't find anything in the documentation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me look in the orgmode source and see what they do.