Update modules/lang/*

This commit is contained in:
Henrik Lissner 2017-02-19 18:57:16 -05:00
parent f0adef1b01
commit e14e25ecb4
68 changed files with 1487 additions and 750 deletions

View file

@ -0,0 +1,49 @@
;; -*- no-byte-compile: t; -*-
;;; lang/sh/config.el
(defvar sh-extra-font-lock--keywords
`((+sh--match-var-in-double-quoted-string
(2 font-lock-variable-name-face prepend))
(,(concat
"\\<"
(regexp-opt '("sudo" "echo" "ls" "sleep" "tee" "cd" "cat" "service"))
"\\>")
(0 'font-lock-builtin-face))))
;;;###autoload
(defun +sh--in-double-quoted-string-p ()
"Non-nil if point in inside a double-quoted string."
(let ((state (syntax-ppss)))
(eq (nth 3 state) ?\")))
;;;###autoload
(defun +sh--match-var-in-double-quoted-string (limit)
"Search for variables in double-quoted strings bounded by LIMIT."
(let (res)
(while
(and (setq res
(re-search-forward
"\\$\\({#?\\)?\\([[:alpha:]_][[:alnum:]_]*\\|[-#?@!]\\)"
limit t))
(not (+sh--in-double-quoted-string-p))))
res))
;;;###autoload
(defun +sh|extra-fontify ()
"Activate sh-extra-font-lock."
(interactive)
(font-lock-add-keywords nil sh-extra-font-lock--keywords)
(if (fboundp 'font-lock-flush)
(font-lock-flush)
(when font-lock-mode
(with-no-warnings
(font-lock-fontify-buffer)))))
;;;###autoload
(defun +sh/repl ()
"Open a shell REPL."
(let* ((dest-sh (symbol-name sh-shell))
(sh-shell-file dest-sh))
(sh-shell-process t)
(with-current-buffer "*shell*"
(rename-buffer (format "*shell [%s]*" dest-sh)))))

View file

@ -0,0 +1,14 @@
;;; lang/sh/boostrap.el
(bootstrap!
:title "{z,ba}sh"
:desc "Sets up the zshdb and bashdb debuggers, and shell-check"
:if-debian
(sudo "apt-get update && apt-get install zshdb bashdb spellcheck")
:if-arch
(sudo "pacman --noconfirm --needed -S zshdb bashdb shellcheck")
:if-macos
(sh "brew install zshdb bashdb"))

View file

@ -1,24 +1,26 @@
;;; module-sh.el
;;; lang/sh/config.el
(use-package sh-script
:mode (("\\.\\(ba\\|z\\)sh$" . sh-mode)
("/\\.?z\\(sh\\(/.*\\|$\\)\\|profile\\|log\\(in\\|out\\)\\|sh\\(rc\\|env\\)\\)$" . sh-mode)
("/\\.?bash\\(/.*\\|rc\\|_profile\\)$" . sh-mode)
("/\\.?xinitrc$" . sh-mode)
(@def-package sh-script ; built-in
:mode (("\\.zsh$" . sh-mode)
("/bspwmrc$" . sh-mode))
:init (add-hook! sh-mode '(flycheck-mode doom|sh-extra-font-lock-activate highlight-numbers-mode))
:init
(@add-hook sh-mode '(flycheck-mode highlight-numbers-mode +sh|extra-fontify))
:config
(def-company-backend! sh-mode (shell))
(def-electric! sh-mode :words ("else" "elif" "fi" "done" "then" "do" "esac" ";;"))
(def-repl! sh-mode doom/inf-shell)
(@set :company-backend 'sh-mode '(company-shell))
(@set :electric 'sh-mode :words "else" "elif" "fi" "done" "then" "do" "esac" ";;")
(@set :repl 'sh-mode '+sh/repl)
(setq sh-indent-after-continuation 'always)
;; [pedantry intensifies]
(add-hook! sh-mode (setq mode-name "sh")))
(@add-hook sh-mode (setq mode-name "sh"))
(use-package company-shell
(defun +sh|detect-zsh ()
(when (and buffer-file-name (string-match-p "\\.zsh\\'" buffer-file-name))
(sh-set-shell "zsh")))
(add-hook 'sh-mode-hook '+sh|detect-zsh))
(@def-package company-shell
:after sh-script
:config (setq company-shell-delete-duplicates t))
(provide 'module-sh)
;;; module-sh.el ends here

View file

@ -0,0 +1,5 @@
;; -*- no-byte-compile: t; -*-
;;; lang/sh/packages.el
(when (@featurep :completion company)
(@package company-shell))

12
modules/lang/sh/setup.sh Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env bash
source VARS
#
echo "Setting up zsh/bash (zshdb, bashdb)"
if is-mac; then
brew install zshdb bashdb
elif is-arch; then
sudo pacman --noconfirm -S zshdb bashdb
fi