Code fence auto indent and Tab indent
Hi. I found that when coding in javascript in code fence, the auto indent seems to be 2 spaces. How can I customize the auto indent to be 4 spaces? And another question, how can I set the Tab indent to be 4 spaces? Thanks.
Hi bro, have you figure out this issue?
I found the same case in Java code fence.
According to CodeMirror
indentUnit: integer How many spaces a block (whatever that means in the edited language) should be indented. The default is 2.
So I think this could be figured by modify a specific preference file. I tried to search any possible file to change the default Tab indent and auto indent.
However, nothing help yet.
We should expose the "indent side" option of codemirror in future updates.
I am now having this issue with PHP and Go code as well. This is especially problematic for Go since the language requires tabs, not spaces, and the PHP standard for many projects is tabs as well. (This is important for me since I'm actually extracting runnable code from my code blocks, and use Typora to write it as well.)
It looks like these settings in CodeMirror are what determine the indentation. (Specifically, indentUnit, smartIndent, tabSize, and indentWithTabs.) Exposing them -- even if only via the "advanced" JSON-based settings -- would allow those of us who do use Typora as a code editor to tune these settings to our needs.
Added option for "Indent Size for Code"
Hi, has this function been implemented?
Yes, but only for code fences and source code mode
Hi, can you guys add an option for tab indentation instead of space indentation?
Yes, but only for code fences and source code mode
I would love being able to change tab size for 'plain text' too, is it possible? Sometimes working with subtopics in my notes leaves a lot of empty and usuless spaces. (current Tab Size for #write is 8 characters)

Could we set tab size greater than 5 in code block? Like 8?

Yes, but only for code fences and source code mode
But I still got tabs rather than spaces after "Tab" pressed.
put into #579
我找到一个解决办法:利用 expand 命令,支持 Linux 和 macOS 在 Git 提交变动的时候,自动将文本的 tab => 4个空格。
chmod +x .git/hooks/pre-commit
#!/bin/sh
# 01、得到项目根目录,Get project root directory
PROJECT_HOME=$(
cd "$(dirname "$0")" || exit
cd ../../
pwd
)
# echo "${PROJECT_HOME}" >>~/Desktop/git_hook.log
# 02、获取修改的文件的子路径,Get the sub path of the modified file
STAGE_FILES=$(git diff HEAD --name-only --diff-filter=ACM -- '*.md' '*.py') # 限制后缀文件类型
# echo "${STAGE_FILES}" >>~/Desktop/git_hook.log
TMPFILE=$(mktemp) # 随机临时文件,Random temporary file
# echo "TMPFILE${TMPFILE}" >>~/Desktop/git_hook.log
if test ${#STAGE_FILES} -gt 0; then
# echo '开始替换 Tab => 4个空格' >>~/Desktop/git_hook.log
OLDIFS="$IFS" # 备份旧的 IFS 变量
IFS=$'\n' # 修改分隔符为换行符
for FILE in $STAGE_FILES; do
FULE_PATH="${PROJECT_HOME}/${FILE}"
# echo "expanding ${FULE_PATH}" >>~/Desktop/git_hook.log
expand -t 4 "${FULE_PATH}" >"${TMPFILE}" # 利用系统 expand 将 Tab 转成 4个空格,并保存进临时文件
cp "${TMPFILE}" "${FULE_PATH}" # 利用临时文件覆盖,Tip:相同内容不会造成 diff 时,整个文件都变动的,放心用!
git add "${FULE_PATH}"
# $? 表示上一个任务的执行结果,正常执行返回 0
if [ $? == 0 ]; then # $?:Indicates the execution result of the last command
# echo '替换完毕 ...' >>~/Desktop/git_hook.log
fi
done
IFS="$OLDIFS" # 还原 IFS 变量
fi
exit 0 # Return 0,Indicates normal
@lhsaq2009 windows 震怒