Skip to content

Support sheband and tangle mode header tag #939

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 17 commits into
base: master
Choose a base branch
from

Conversation

SjB
Copy link
Contributor

@SjB SjB commented Mar 19, 2025

Summary

Add shebang and tangle-mode source block header tags

Related Issues

New features to enable features in org-mode

Related #

https://orgmode.org/manual/Extracting-Source-Code.html

Closes #

Changes

Changes the structure of the tangle_info table.

@kristijanhusak kristijanhusak force-pushed the support_sheband_and_tangle_mode_header_tag branch from 113cc16 to 67667a8 Compare March 25, 2025 19:20
@SjB SjB force-pushed the support_sheband_and_tangle_mode_header_tag branch from 67667a8 to 160fe5f Compare March 29, 2025 14:03
Copy link
Member

@kristijanhusak kristijanhusak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Generally looks good, but I have some questions and suggestions.

Comment on lines 83 to 87
local shebang = info.header_args[':shebang']
if shebang then
shebang = shebang:gsub('[\'"]', '')
table.insert(parsed_content, 1, shebang)
end
Copy link
Member

Choose a reason for hiding this comment

The 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 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing chmod after the file is created, lets pass down the mode as an argument to utils.writefile and pass it there when creating the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sound good, I'm make the changes

SjB added 13 commits April 16, 2025 00:30
Add the ability to include a shebang line at the beginning of tangled code files
by supporting the `:shebang` header argument. The shebang value is cleaned of
quotes and inserted as the first line of the tangled content.
This header allow the creator to change the generated file permissions.
When tangling code blocks to files, automatically create parent directories
when the :mkdirp header argument is set to 'yes'.
Coding style requires single quotes
Add the ability to include a shebang line at the beginning of tangled code files
by supporting the `:shebang` header argument. The shebang value is cleaned of
quotes and inserted as the first line of the tangled content.
They keep showing up.
@SjB SjB force-pushed the support_sheband_and_tangle_mode_header_tag branch from e84d8a8 to fdfb3c8 Compare April 16, 2025 04:31
@SjB
Copy link
Contributor Author

SjB commented Apr 16, 2025

The orgmode docs describe 3 styles of tangle-mode values: ls-style, chmod style, and octal. All three style are now supported, however, I'm still using the vim.loop.fs_chmod function, as I can't seem to support all the requirements with the utils.writefile function

example of the three modes

#+BEGIN_SRC text :tangle result-octal.txt :tangle-mode o700
octal mode
#+END_SRC

#+BEGIN_SRC text :tangle result-ls-style.txt :tangle-mode rw-rw----
ls style
#+END_SRC

#+BEGIN_SRC text :tangle result-chmod-style.txt :tangle-mode ug+wx,u+wr,o+x
chmod style
#+END_SRC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants