summaryrefslogtreecommitdiff
path: root/after/ftplugin
diff options
context:
space:
mode:
authortalha <talha@talhaamir.xyz>2026-07-23 21:12:35 +0500
committertalha <talha@talhaamir.xyz>2026-07-23 21:12:35 +0500
commit70fe2441aa025243e29d47aabe1b6674c4e0ed71 (patch)
tree526b58ec31ce6dd0075fe1e76e6828a5ab51ae14 /after/ftplugin
parent75b48fc3247b412bb1580c47e96022cffdc8ba9a (diff)
Updated config
Diffstat (limited to 'after/ftplugin')
-rw-r--r--after/ftplugin/html.lua138
1 files changed, 138 insertions, 0 deletions
diff --git a/after/ftplugin/html.lua b/after/ftplugin/html.lua
new file mode 100644
index 0000000..bfc21d4
--- /dev/null
+++ b/after/ftplugin/html.lua
@@ -0,0 +1,138 @@
+-- html snippets
+function Snippets(snipType, value)
+ snippet = ""
+ if snipType == "comment" then
+ snippet = [[<!-- -->]]
+ elseif snipType == "tag" then
+ snippet = string.format("<%s></%s>", value, value)
+ elseif snipType == "linebreak" then
+ snippet = [[<br>]]
+ elseif snipType == "hrline" then
+ snippet = [[<hr>]]
+ elseif snipType == "link" then
+ snippet = string.format([[<a href="%s">%s</a>]],
+ value["url"], value["label"]
+ )
+ elseif snipType == "pieces" then
+ if value == "init" then
+ snippet = [[
+<!DOCTYPE html>
+<html>
+<head>
+ <title></title>
+ <link rel="stylesheet" href="StyleSheetName.css"/>
+</head>
+<body>
+</body>
+</html>
+ ]]
+ elseif value == "paper" then
+ snippet = [[
+<style>
+html {
+ background: #ffffd7;
+}
+</style>
+ ]]
+ elseif value == "cjHeader" then
+ snippet = string.format([[
+<section>
+ <h1>_title_</h1>
+ <p>
+ <i>_subtitle_</i><br>
+ %s<br>
+ <a href="index.html">The Cursory Journal</a>
+ <hr>
+ </p>
+</section>
+ ]], os.date("%Y/%m/%d"))
+ end
+ end
+ return snippet
+end
+
+function JumpInTag()
+ vim.cmd("normal! f>l")
+end
+
+-- keymaps to insert snippets
+vim.keymap.set('i', "<M-s><M-c>", function()
+ WriteText(Snippets("comment"))
+end, {noremap=true})
+
+vim.keymap.set('i', "<M-s><M-i>", function()
+ WriteText(Snippets("tag", "i"))
+ JumpInTag()
+end, {noremap=true})
+
+vim.keymap.set('i', "<M-s><M-b>", function()
+ WriteText(Snippets("tag", "b"))
+ JumpInTag()
+end, {noremap=true})
+
+vim.keymap.set('i', "<M-s><M-/>", function()
+ WriteText(Snippets("linebreak"))
+end, {noremap=true})
+
+vim.keymap.set('i', "<M-s><M-->", function()
+ WriteText(Snippets("hrline"))
+end, {noremap=true})
+
+vim.keymap.set('i', "<M-s><M-t>", function()
+ inp = vim.fn.input("Tag: ", "", "file")
+ WriteText(Snippets("tag", inp))
+ JumpInTag()
+end, {remap=true})
+
+vim.keymap.set('i', "<M-s><M-l>", function()
+ url = vim.fn.input("URL: ", "", "file")
+ label = vim.fn.input("label: ", "", "file")
+ value = {}
+ value.url = url
+ value.label = label
+ WriteText(
+ Snippets("link", value)
+ )
+ JumpInTag()
+end, {remap=true})
+
+
+vim.keymap.set('i', "<M-s><M-d>", function()
+ dt = os.date("%Y/%m/%d")
+ WriteText(dt)
+end)
+
+vim.keymap.set('i', "<M-s><M-p>", function()
+ name = vim.fn.input("name: ", "", "file")
+ WriteLines(
+ StrSplit(Snippets("pieces", name), '\n')
+ )
+end)
+
+function WriteText(toWrite)
+ if not toWrite then
+ return
+ end
+ local posYX = vim.api.nvim_win_get_cursor(0)
+ vim.api.nvim_buf_set_text(0, posYX[1]-1, posYX[2], posYX[1]-1, posYX[2], { toWrite })
+end
+
+function WriteLines(toWrite)
+ if not toWrite then
+ return
+ end
+ local posYX = vim.api.nvim_win_get_cursor(0)
+ print(posYX[0], posYX[1], posYX[2])
+ vim.api.nvim_buf_set_lines(0, posYX[1]-1, posYX[1]-1, true, toWrite)
+end
+
+function StrSplit(inpstr, sep)
+ if not sep then
+ sep = "%s"
+ end
+ local str_list = {}
+ for str in string.gmatch(inpstr, "([^"..sep.."]+)") do
+ table.insert(str_list, str)
+ end
+ return str_list
+end