استمرار القائمة التلقائية وتنسيق Neovim ، مدعوم من Lua
يمكن تفسير هذا السؤال بطريقتين. لماذا قمت بإنشاء ألقائي ، ولماذا يجب أن تستخدم الأوتوليست.
يبدو الأمر بسيطًا ، لكن كل ما أردته هو المكون الإضافي للاستمرار في LUA. Bullets.vim يعمل ، ولكنه مكتوب في Vimscript ويبلغ طوله أكثر من ألف خط. وغني عن القول ، لم أتمكن من العثور على واحدة مناسبة ، لذلك قررت إنشاء بلدي.
ملفات autolist.nvim's
صغيرة نسبيًا ، مع الملفات كاملة مع التعليقات والتنسيق. يسعى إلى أن يكون الحد الأدنى قدر الإمكان ، مع تنفيذ الوظائف الأساسية للقوائم التلقائية ، وتنفذ السياق الذي يدرك إعادة ترقيم/وضع علامات على إدخالات القائمة ، لأخذ عقلك عن التنسيق ، وجعلها تعمل في الخلفية أثناء كتابة أفكارك.
هذا يستخدم lazy.nvim ، ولكن يمكنك تكييفه مع مديري الحزم الآخرين أيضًا:
{
" gaoDean/autolist.nvim " ,
ft = {
" markdown " ,
" text " ,
" tex " ,
" plaintex " ,
" norg " ,
},
config = function ()
require ( " autolist " ). setup ()
vim . keymap . set ( " i " , " <tab> " , " <cmd>AutolistTab<cr> " )
vim . keymap . set ( " i " , " <s-tab> " , " <cmd>AutolistShiftTab<cr> " )
-- vim.keymap.set("i", "<c-t>", "<c-t><cmd>AutolistRecalculate<cr>") -- an example of using <c-t> to indent
vim . keymap . set ( " i " , " <CR> " , " <CR><cmd>AutolistNewBullet<cr> " )
vim . keymap . set ( " n " , " o " , " o<cmd>AutolistNewBullet<cr> " )
vim . keymap . set ( " n " , " O " , " O<cmd>AutolistNewBulletBefore<cr> " )
vim . keymap . set ( " n " , " <CR> " , " <cmd>AutolistToggleCheckbox<cr><CR> " )
vim . keymap . set ( " n " , " <C-r> " , " <cmd>AutolistRecalculate<cr> " )
-- cycle list types with dot-repeat
vim . keymap . set ( " n " , " <leader>cn " , require ( " autolist " ). cycle_next_dr , { expr = true })
vim . keymap . set ( " n " , " <leader>cp " , require ( " autolist " ). cycle_prev_dr , { expr = true })
-- if you don't want dot-repeat
-- vim.keymap.set("n", "<leader>cn", "<cmd>AutolistCycleNext<cr>")
-- vim.keymap.set("n", "<leader>cp", "<cmd>AutolistCycleNext<cr>")
-- functions to recalculate list on edit
vim . keymap . set ( " n " , " >> " , " >><cmd>AutolistRecalculate<cr> " )
vim . keymap . set ( " n " , " << " , " <<<cmd>AutolistRecalculate<cr> " )
vim . keymap . set ( " n " , " dd " , " dd<cmd>AutolistRecalculate<cr> " )
vim . keymap . set ( " v " , " d " , " d<cmd>AutolistRecalculate<cr> " )
end ,
},
-|+|*
أو 1.|2.|3.
)enter
/ return
وسيتم إنشاء إدخال قائمة جديد تلقائيًاenter
/ return
في إدخال قائمة فارغة سيحذفه ، مما يتركك مع جملة جديدة جديدة. - [x] checkboxes can be toggled with ` :AutolistToggleCheckbox ` , which is bound to ` return ` in normal mode if you used the default mappings
1 . [x] these can also be numbered
a) [ ] or these can work too
b) [ x ] see?
I. Roman numerals are also supported
II. Just press enter, and autolist will do the calculations for you
MX. All the way up
MXI. to infinity
MXII. It really will continue forever
MXIII. -I think
- you can cycle the type of the list with ` :AutolistCycleNext ` and ` :AutolistCyclePrev `
- below is a copy of this list after cycling twice
1 . you can cycle the type of the list with ` :AutolistCycleNext ` and ` :AutolistCyclePrev `
2 . below is a copy of this list after cycling twice
local list_patterns = {
neorg_1 = " %- " ,
neorg_2 = " %-%- " ,
neorg_3 = " %-%-%- " ,
neorg_4 = " %-%-%-%- " ,
neorg_5 = " %-%-%-%-%- " ,
unordered = " [-+*] " , -- - + *
digit = " %d+[.)] " , -- 1. 2. 3.
ascii = " %a[.)] " , -- a) b) c)
roman = " %u*[.)] " , -- I. II. III.
latex_item = " \ item " ,
}
local default_config = {
enabled = true ,
colon = { -- if a line ends in a colon
indent = true , -- if in list and line ends in `:` then create list
indent_raw = true , -- above, but doesn't need to be in a list to work
preferred = " - " , -- what the new list starts with (can be `1.` etc)
},
cycle = { -- Cycles the list type in order
" - " , -- whatever you put here will match the first item in your list
" * " , -- for example if your list started with a `-` it would go to `*`
" 1. " , -- this says that if your list starts with a `*` it would go to `1.`
" 1) " , -- this all leverages the power of recalculate.
" a) " , -- i spent many hours on that function
" I. " , -- try it, change the first bullet in a list to `a)`, and press recalculate
},
lists = { -- configures list behaviours
-- Each key in lists represents a filetype.
-- The value is a table of all the list patterns that the filetype implements.
-- See how to define your custom list below in the readme.
-- You must put the file name for the filetype, not the file extension
-- To get the "file name", it is just =:set filetype?= or =:se ft?=.
markdown = {
list_patterns . unordered ,
list_patterns . digit ,
list_patterns . ascii , -- for example this specifies activate the ascii list
list_patterns . roman , -- type for markdown files.
},
text = {
list_patterns . unordered ,
list_patterns . digit ,
list_patterns . ascii ,
list_patterns . roman ,
},
norg = {
list_patterns . neorg_1 ,
list_patterns . neorg_2 ,
list_patterns . neorg_3 ,
list_patterns . neorg_4 ,
list_patterns . neorg_5 ,
},
tex = { list_patterns . latex_item },
plaintex = { list_patterns . latex_item },
},
checkbox = {
left = " %[ " , -- the left checkbox delimiter (you could change to "%(" for brackets)
right = " %] " , -- the right checkbox delim (same customisation as above)
fill = " x " , -- if you do the above two customisations, your checkbox could be (x) instead of [x]
},
-- this is all based on lua patterns, see "Defining custom lists" for a nice article to learn them
}
فيما يلي جميع الوظائف العامة:
AutolistNewBullet
: يضيف رصاصة جديدة على الخط الحاليAutolistRecalculate
: إعادة حساب قائمة مرتبةAutolistToggleCheckbox
: تبديل خانة اختيار على السطر الحاليAutolistCycleNext
: دورات نوع القائمة إلى الأمام وفقًا لـ config.cycle
AutolistCyclePrev
: أعلاه ، ولكن للخلفAutolistTab
: لديه حالة استخدام خاصة حيث تريد المسافة البادئة للقائمة عند الضغط على علامة التبويب. إذا كنت ترغب في الحصول على مسافة بادئة للقائمة عند الضغط على <ct>
، فأنت بحاجة فقط إلى تعيين <ct>
إلى AutolistRecalculate
لأن AutolistTab
يحول علامة تبويب إلى <ct>
مع إعادة حساب.AutolistShiftTab
: نفس الشيء على النحو الوارد أعلاه ، يستخدم لتكرار معالجات النصوص. تعيين <s-tab>
إلى ذلك سيقوم بتحويله إلى <cd>AutolistRecalculate
. جميع الوظائف الموضحة أعلاه لها نظرائهم في LUA والتي هي مجرد إصدارات حالة الأفعى من أوامر Case Pascal. على سبيل المثال ، يتطلب نظير علبة الأفعى AutolistNewBullet
require("autolist").new_bullet()
هناك وظيفتان خاصتان لـ LUA: require("autolist").cycle_next_dr
require("autolist").cycle_prev_dr
، والتي توفر إصدارات قابلة للتكرار من النقطة من AutolistCycleNext
و AutolistCyclePrev
.
باختصار ، كل ما عليك فعله هو جعل مطابقة نمط LUA تتيح Autolist للعثور على علامة القائمة الجديدة.
إليك مقالًا غير باد عن أنماط LUA ، ولكن يمكنك العثور على أمثلة لهذه الأنماط في قسم الأنماط المحملة مسبقًا.
إليك كيفية تحديد قائمتك المخصصة:
local my_list_patterns = {
test = " %a[.)] "
}
require ( ' autolist ' ). setup ({
lists = {
markdown = {
" %a[.)] " , -- insert your custom lua pattern here
my_list_patterns . test , -- or use a variable
},
},
}
})
الآن سيتم تطبيق نمط LUA الخاص بك (في هذه الحالة %a[.)]
الذي يتطابق مع قوائم ASCII) على ملفات تخفيض الطلب.
هل لديها رسم خرائط لتبديل خانة اختيار مثل الرصاص. نعم.
هل تدعم قوائم مربعات الاختيار؟ نعم.
هل وجدت أن المكون الإضافي ينهار عند استخدام الأوتوليست؟ انظر #43. تحتاج بشكل أساسي إلى التأكد من أن الأحمال التلقائية بعد جميع الإضافات الأخرى. إذا لم ينجح ذلك ، فلا تتردد في إنشاء مشكلة جديدة. أيضًا ، تأكد من أن رسملة التعيينات الخاصة بك صحيحة ، أو لن تكتشف Autolist المكونات الإضافية الأخرى ( <cr>
يجب أن تكون <CR>
).
مستوحاة من هذا الجوهر
"جميع البرامج تضيف الميزات حتى تكون معقدة بشكل مزعج. ثم يتم استبدالها بحل" أبسط "يضيف الميزات حتى يكون معقدًا تمامًا."
أبحث عن مساهمين لأن لديّ عمل مدرسي مما يعني أنني لا أستطيع أحيانًا مواكبة القضايا