Skip to content

Commit

Permalink
Toggle comment feature, special char hotkeys, fix getDocPath bug
Browse files Browse the repository at this point in the history
  • Loading branch information
genotrance committed May 12, 2019
1 parent 71b2b1c commit 34f0974
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ newWindow - open a new editor window
closeWindow - close current window
```

Buffer actions:
```
toggleComment - comment / uncomment selection or line
```

Shell:
```
! command - Run command and print output to new buffer
Expand Down
2 changes: 2 additions & 0 deletions feud.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ hotkey ^l last
hotkey ^r togglePopup !
hotkey ^+r togglePopup |

hotkey ^/ toggleComment

# Tabs and indents
# https://www.scintilla.org/ScintillaDoc.html#TabsAndIndentationGuides
hook postFileSwitch eMsg SCI_SETUSETABS 0
Expand Down
56 changes: 56 additions & 0 deletions plugins/server/buffer.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os, strformat, strutils

import "../.."/src/pluginapi

proc toggleComment(plg: var Plugin) {.feudCallback.} =
var
selStart = plg.ctx.msg(plg.ctx, SCI_GETSELECTIONSTART)
selEnd = plg.ctx.msg(plg.ctx, SCI_GETSELECTIONEND)
selStartLine = plg.ctx.msg(plg.ctx, SCI_LINEFROMPOSITION, selStart)
selEndLine = plg.ctx.msg(plg.ctx, SCI_LINEFROMPOSITION, selEnd)

selStart = plg.ctx.msg(plg.ctx, SCI_POSITIONFROMLINE, selStartLine)
if selEnd == 0:
selEnd = plg.ctx.msg(plg.ctx, SCI_GETLINEENDPOSITION, selStartLine)
else:
let
selEndLineStart = plg.ctx.msg(plg.ctx, SCI_POSITIONFROMLINE, selEndLine)
if selEnd == selEndLineStart:
selEndLine -= 1
selEnd = plg.ctx.msg(plg.ctx, SCI_GETLINEENDPOSITION, selEndLine)

if selStart != selEnd:
var
length = selEnd - selStart
data = alloc0(length+1)
sel: seq[string]
defer: data.dealloc()

discard plg.ctx.msg(plg.ctx, SCI_SETTARGETRANGE, selStart, selEnd.toPtr)
discard plg.ctx.msg(plg.ctx, SCI_GETTARGETTEXT, 0, data)
sel = ($cast[cstring](data)).splitLines(keepEol = true)

if sel.len != 0:
let
docPath = plg.getCbResult("getDocPath")

if docPath.len != 0:
let
commentLine = plg.getCbResult(&"getCommentLine {docPath.quoteShell}")
commentLen = commentLine.len

if commentLen != 0:
for i in 0 .. sel.len-1:
if sel[i].startsWith(commentLine):
sel[i] = sel[i][commentLen .. ^1]
elif sel[i].strip().len != 0:
sel[i] = commentLine & sel[i]

let
newSel = sel.join("")
discard plg.ctx.msg(plg.ctx, SCI_REPLACETARGET, newSel.len, newSel.cstring)

feudPluginDepends(["config", "window"])

feudPluginLoad()

2 changes: 1 addition & 1 deletion plugins/server/file.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ proc getDocPath(plg: var Plugin) {.feudCallback.} =
if docid != -1:
plg.ctx.cmdParam = @[docs.doclist[docid].path]
else:
plg.ctx.cmdParam = @[""]
plg.ctx.cmdParam = @[]

proc setCurrentDir(plg: var Plugin, dir: string) =
var
Expand Down
7 changes: 6 additions & 1 deletion plugins/server/gist.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ proc gist(plg: var Plugin) {.feudCallback.} =
var
client = newHttpClient(proxy = getProxy())
url = "http://ix.io"
name = plg.getCbResult("getDocPath").extractFilename()
path = plg.getCbResult("getDocPath")
name =
if path.len != 0:
path.extractFilename()
else:
"test.txt"
post = "name:1=" & name & "&f:1="
success = false
gistUrl = ""
Expand Down
16 changes: 10 additions & 6 deletions plugins/server/window/hotkey.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const VKTable = {
"F1": 112, "F2": 113, "F3": 114, "F4": 115, "F5": 116, "F6": 117, "F7": 118, "F8": 119, "F9": 120, "F10": 121,
"F11": 122, "F12": 123, "F13": 124, "F14": 125, "F15": 126, "F16": 127, "F17": 128, "F18": 129, "F19": 130, "F20": 131,
"F21": 132, "F22": 133, "F23": 134, "F24": 135, "Tab": 9, "PgDn": 34, "PgUp": 35, "Home": 36, "End": 35
}.toTable()
const
VKTable = {
"F1": 112, "F2": 113, "F3": 114, "F4": 115, "F5": 116, "F6": 117, "F7": 118, "F8": 119, "F9": 120, "F10": 121,
"F11": 122, "F12": 123, "F13": 124, "F14": 125, "F15": 126, "F16": 127, "F17": 128, "F18": 129, "F19": 130, "F20": 131,
"F21": 132, "F22": 133, "F23": 134, "F24": 135, "Tab": 9, "PgDn": 34, "PgUp": 35, "Home": 36, "End": 35,

";": 186, ":": 186, "+": 187, ",": 188, "<": 188, "-": 189, "_": 189, ".": 190, ">": 190, "/": 191, "?": 191,
"~": 192, "`": 192, "[": 219, "{": 219, "\\": 220, "|": 220, "]": 221, "}": 221, "'": 222, "\"": 222
}.toTable()

proc hotkey(plg: var Plugin) {.feudCallback.} =
var
Expand Down Expand Up @@ -41,7 +45,7 @@ proc hotkey(plg: var Plugin) {.feudCallback.} =
of '+':
fsModifiers = fsModifiers or MOD_SHIFT
else:
if spec.len != 0 or i != hotkey.len-1:
if spec.len != 0 or i != hotkey.len-1 or VKTable.hasKey($hotkey[i]):
spec &= hotkey[i]
else:
vk = hotkey[i].toUpperAscii
Expand Down

0 comments on commit 34f0974

Please sign in to comment.