Skip to content

Commit c405f62

Browse files
committed
editors: Add more editor support including emacs and golanf
1 parent 3a3811a commit c405f62

13 files changed

+656
-67
lines changed

editors/Lite/install.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeuo pipefail
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
EXT=lua
7+
FILE=$SCRIPT_DIR/*.$EXT
8+
VERSION=1.0
9+
EDITOR=Lite-XL
10+
INSTALL=$HOME/.config/lite-xl/plugins/piccodescript
11+
12+
log() {
13+
printf "[INFO] %s\n" "$1"
14+
}
15+
16+
splash() {
17+
log " "
18+
log "▄▖▘ ▌ ▄▖ ▘ ▗ "
19+
log "▙▌▌▛▘▛▘▛▌▛▌█▌▚ ▛▘▛▘▌▛▌▜▘"
20+
log "▌ ▌▙▖▙▖▙▌▙▌▙▖▄▌▙▖▌ ▌▙▌▐▖"
21+
log ""
22+
log " "
23+
log " $VERSION "
24+
log " "
25+
log " ===== "
26+
log " BUILD AND "
27+
log " INSTALLATION SCRIPT "
28+
log " FOR "
29+
log " $EDITOR "
30+
log " ===== "
31+
log " "
32+
log " (c) Hexaredecimal "
33+
log " "
34+
}
35+
36+
37+
checkInstallDir() {
38+
if [ -d "$INSTALL" ]; then
39+
log "$INSTALL is already present"
40+
else
41+
log "Creating $INSTALL directory"
42+
mkdir -p $INSTALL
43+
log "Done creating $INSTALL"
44+
fi
45+
}
46+
47+
copyToDest() {
48+
log "copying $1 to $2"
49+
cp -r $1 $2
50+
}
51+
52+
53+
install() {
54+
checkInstallDir
55+
log "Installation stated"
56+
copyToDest $FILE $INSTALL
57+
log "Installation is done"
58+
}
59+
60+
finalMessage() {
61+
log ""
62+
log "Thank you for installing the piccodescript mode for $EDITOR"
63+
}
64+
65+
handle_error() {
66+
log "Something went wrong"
67+
log "Aborting"
68+
}
69+
70+
trap handle_error ERR
71+
72+
main() {
73+
splash
74+
install
75+
finalMessage
76+
}
77+
78+
main

editors/Lite/language_piccodescript.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ syntax.add {
2222
["if"] = "keyword",
2323
["else"] = "keyword",
2424
["do"] = "keyword",
25-
["when"] = "keyword",
25+
["when"] = "keyword",
2626
["is"] = "keyword",
27-
["await"] = "keyword",
27+
["return"] = "keyword",
28+
["catch"] = "keyword",
29+
["await"] = "keyword",
2830
["true"] = "literal",
2931
["false"] = "literal",
3032
},

editors/emacs/install.sh

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bash
2+
3+
set -Eeuo pipefail
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
EXT=el
7+
FILE=$SCRIPT_DIR/*.$EXT
8+
VERSION=1.0
9+
EDITOR=Emacs
10+
INSTALL=$HOME/.emacs.local
11+
CONFIG=$HOME/.emacs.d/init.el
12+
13+
INSTALL_LINE="\n(add-to-list 'load-path \"~/.emacs.local\")\n\
14+
(load-file \"~/.emacs.local/piccodescript-mode.el\")\n\
15+
(require 'piccode-mode)\n\
16+
(add-to-list 'auto-mode-alist '(\"\\\\.pics\\\\'\" . piccode-mode))\n\n"
17+
18+
log() {
19+
printf "[INFO] %s\n" "$1"
20+
}
21+
22+
splash() {
23+
log " "
24+
log "▄▖▘ ▌ ▄▖ ▘ ▗ "
25+
log "▙▌▌▛▘▛▘▛▌▛▌█▌▚ ▛▘▛▘▌▛▌▜▘"
26+
log "▌ ▌▙▖▙▖▙▌▙▌▙▖▄▌▙▖▌ ▌▙▌▐▖"
27+
log ""
28+
log " "
29+
log " $VERSION "
30+
log " "
31+
log " ===== "
32+
log " BUILD AND "
33+
log " INSTALLATION SCRIPT "
34+
log " FOR "
35+
log " $EDITOR "
36+
log " ===== "
37+
log " "
38+
log " (c) Hexaredecimal "
39+
log " "
40+
}
41+
42+
43+
writeConfig() {
44+
if grep -q "(require 'piccode-mode)'" "$CONFIG"; then
45+
log "Note: Plugin already activated"
46+
else
47+
echo -e $INSTALL_LINE >> $CONFIG
48+
fi
49+
}
50+
51+
checkConfig() {
52+
if ! [[ -f "$CONFIG" ]]; then
53+
log "Error: Unable to find $CONFIG."
54+
log "Add the following lines to your config."
55+
log "$INSTALL_LINE"
56+
else
57+
writeConfig
58+
fi
59+
}
60+
61+
checkInstallDir() {
62+
if [ -d "$INSTALL" ]; then
63+
log "$INSTALL is already present"
64+
else
65+
log "Creating $INSTALL directory"
66+
mkdir $INSTALL
67+
log "Done creating $INSTALL"
68+
fi
69+
}
70+
71+
copyToDest() {
72+
log "copying $1 to $2"
73+
cp -r $1 $2
74+
}
75+
76+
rootCopyToDest() {
77+
log "root copying $1 to $2"
78+
sudo cp -r $1 $2
79+
}
80+
81+
82+
install() {
83+
checkInstallDir
84+
log "Installation stated"
85+
copyToDest $FILE $INSTALL
86+
log "Installation is done"
87+
checkConfig
88+
}
89+
90+
finalMessage() {
91+
log ""
92+
log "Thank you for installing the piccodescript mode for $EDITOR"
93+
}
94+
95+
handle_error() {
96+
log "Something went wrong"
97+
log "Aborting"
98+
}
99+
100+
trap handle_error ERR
101+
102+
main() {
103+
splash
104+
install
105+
finalMessage
106+
}
107+
108+
main
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
(require 'subr-x)
2+
3+
(defvar piccode-mode-syntax-table
4+
(let ((table (make-syntax-table)))
5+
;; C/C++ style comments
6+
(modify-syntax-entry ?/ ". 124b" table)
7+
(modify-syntax-entry ?* ". 23" table)
8+
(modify-syntax-entry ?\n "> b" table)
9+
;; Preprocessor stuff?
10+
(modify-syntax-entry ?# "." table)
11+
;; Chars are the same as strings
12+
(modify-syntax-entry ?' "\"" table)
13+
table))
14+
15+
(defun piccode-constants ()
16+
'("true" "false" "await"))
17+
18+
(defun piccode-keywords ()
19+
'("import" "module" "if" "else" "when" "is" "do" "catch" "return"))
20+
21+
(defun piccode-font-lock-keywords ()
22+
(list
23+
`(,(regexp-opt (piccode-keywords) 'symbols) . font-lock-keyword-face)
24+
`(,(regexp-opt (piccode-constants) 'symbols) . font-lock-type-face)))
25+
26+
(defun piccode--previous-non-empty-line ()
27+
(save-excursion
28+
(forward-line -1)
29+
(while (and (not (bobp))
30+
(string-empty-p
31+
(string-trim-right
32+
(thing-at-point 'line t))))
33+
(forward-line -1))
34+
(thing-at-point 'line t)))
35+
36+
(defun piccode--indentation-of-previous-non-empty-line ()
37+
(save-excursion
38+
(forward-line -1)
39+
(while (and (not (bobp))
40+
(string-empty-p
41+
(string-trim-right
42+
(thing-at-point 'line t))))
43+
(forward-line -1))
44+
(current-indentation)))
45+
46+
(defun piccode--desired-indentation ()
47+
(let* ((cur-line (string-trim-right (thing-at-point 'line t)))
48+
(prev-line (string-trim-right (piccode--previous-non-empty-line)))
49+
(indent-len 4)
50+
(prev-indent (piccode--indentation-of-previous-non-empty-line)))
51+
(cond
52+
((string-match-p "^\\s-*when\\s-*(.+)" prev-line)
53+
prev-indent)
54+
((and (string-suffix-p "{" prev-line)
55+
(string-prefix-p "}" (string-trim-left cur-line)))
56+
prev-indent)
57+
((string-suffix-p "{" prev-line)
58+
(+ prev-indent indent-len))
59+
((string-prefix-p "}" (string-trim-left cur-line))
60+
(max (- prev-indent indent-len) 0))
61+
((string-suffix-p "->" prev-line)
62+
(if (string-suffix-p "->" cur-line)
63+
prev-indent
64+
(+ prev-indent indent-len)))
65+
((string-suffix-p "->" cur-line)
66+
(max (- prev-indent indent-len) 0))
67+
(t prev-indent))))
68+
69+
;;; TODO: customizable indentation (amount of spaces, tabs, etc)
70+
(defun piccode-indent-line ()
71+
(interactive)
72+
(when (not (bobp))
73+
(let* ((desired-indentation
74+
(piccode--desired-indentation))
75+
(n (max (- (current-column) (current-indentation)) 0)))
76+
(indent-line-to desired-indentation)
77+
(forward-char n))))
78+
79+
(define-derived-mode piccode-mode prog-mode "PiccodeScript"
80+
"PiccodeScript mode for emacs"
81+
:syntax-table piccode-mode-syntax-table
82+
(setq-local font-lock-defaults '(piccode-font-lock-keywords))
83+
(setq-local indent-line-function 'piccode-indent-line)
84+
(setq-local comment-start "// "))
85+
86+
(provide 'piccode-mode)

editors/language_piccodescript.lua

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)