Reorganize modules
This commit is contained in:
parent
50ea98319f
commit
f453b3cee1
55 changed files with 0 additions and 1535 deletions
0
modules/README.md
Normal file
0
modules/README.md
Normal file
|
@ -1,142 +0,0 @@
|
||||||
;;; defuns-cc.el --- for module-cc.el
|
|
||||||
|
|
||||||
(defun doom--c-lineup-inclass (langelem)
|
|
||||||
(let ((inclass (assoc 'inclass c-syntactic-context)))
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (c-langelem-pos inclass))
|
|
||||||
(if (or (looking-at "struct")
|
|
||||||
(looking-at "typedef struct"))
|
|
||||||
'+
|
|
||||||
'++))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/c-lineup-arglist (orig-fun &rest args)
|
|
||||||
"Improve indentation of continued C++11 lambda function opened as argument."
|
|
||||||
(if (and (eq major-mode 'c++-mode)
|
|
||||||
(ignore-errors
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (c-langelem-pos langelem))
|
|
||||||
;; Detect "[...](" or "[...]{". preceded by "," or "(",
|
|
||||||
;; and with unclosed brace.
|
|
||||||
(looking-at ".*[(,][ \t]*\\[[^]]*\\][ \t]*[({][^}]*$"))))
|
|
||||||
0 ; no additional indent
|
|
||||||
(apply orig-fun args)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|init-c/c++-settings ()
|
|
||||||
(when (memq major-mode '(c-mode c++-mode objc-mode))
|
|
||||||
(c-toggle-electric-state -1)
|
|
||||||
(c-toggle-auto-newline -1)
|
|
||||||
(c-set-offset 'substatement-open '0) ; brackets should be at same indentation level as the statements they open
|
|
||||||
(c-set-offset 'inline-open '+)
|
|
||||||
(c-set-offset 'block-open '+)
|
|
||||||
(c-set-offset 'brace-list-open '+) ; all "opens" should be indented by the c-indent-level
|
|
||||||
(c-set-offset 'case-label '+) ; indent case labels by c-indent-level, too
|
|
||||||
(c-set-offset 'access-label '-)
|
|
||||||
(c-set-offset 'inclass 'doom--c-lineup-inclass)
|
|
||||||
(c-set-offset 'arglist-intro '+)
|
|
||||||
(c-set-offset 'arglist-close '0)
|
|
||||||
;; Certain mappings interfere with smartparens and custom bindings
|
|
||||||
(define-key c-mode-map (kbd "DEL") nil)
|
|
||||||
(define-key c-mode-base-map "#" 'self-insert-command)
|
|
||||||
(define-key c-mode-base-map "{" 'self-insert-command)
|
|
||||||
(define-key c-mode-base-map "}" 'self-insert-command)
|
|
||||||
(define-key c-mode-base-map "/" 'self-insert-command)
|
|
||||||
(define-key c-mode-base-map "*" 'self-insert-command)
|
|
||||||
(define-key c-mode-base-map ";" 'self-insert-command)
|
|
||||||
(define-key c-mode-base-map "," 'self-insert-command)
|
|
||||||
(define-key c-mode-base-map ":" 'self-insert-command)
|
|
||||||
(define-key c-mode-base-map "(" 'self-insert-command)
|
|
||||||
(define-key c-mode-base-map ")" 'self-insert-command)
|
|
||||||
|
|
||||||
(define-key c++-mode-map "}" nil)
|
|
||||||
;; FIXME: fix smartparens
|
|
||||||
;; (define-key c++-mode-map ">" nil)
|
|
||||||
(map! :map (c-mode-base-map c++-mode-map) :i ">" 'doom/autoclose->-maybe)
|
|
||||||
(define-key c++-mode-map "<" nil)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/autoclose->-maybe ()
|
|
||||||
"For some reason smartparens won't autoskip >'s, this hack does."
|
|
||||||
(interactive)
|
|
||||||
(if (save-excursion
|
|
||||||
(backward-char)
|
|
||||||
(looking-at-p "[^ \t]>"))
|
|
||||||
(forward-char)
|
|
||||||
(call-interactively 'self-insert-command)))
|
|
||||||
|
|
||||||
(defun doom--copy-face (new-face face)
|
|
||||||
"Define NEW-FACE from existing FACE."
|
|
||||||
(copy-face face new-face)
|
|
||||||
(eval `(defvar ,new-face nil))
|
|
||||||
(set new-face new-face))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|extra-fontify-c++ ()
|
|
||||||
;; We could place some regexes into `c-mode-common-hook', but
|
|
||||||
;; note that their evaluation order matters.
|
|
||||||
;; NOTE modern-cpp-font-lock will eventually supercede some of these rules
|
|
||||||
(font-lock-add-keywords
|
|
||||||
nil '(;; c++11 string literals
|
|
||||||
;; L"wide string"
|
|
||||||
;; L"wide string with UNICODE codepoint: \u2018"
|
|
||||||
;; u8"UTF-8 string", u"UTF-16 string", U"UTF-32 string"
|
|
||||||
("\\<\\([LuU8]+\\)\".*?\"" 1 font-lock-keyword-face)
|
|
||||||
;; R"(user-defined literal)"
|
|
||||||
;; R"( a "quot'd" string )"
|
|
||||||
;; R"delimiter(The String Data" )delimiter"
|
|
||||||
;; R"delimiter((a-z))delimiter" is equivalent to "(a-z)"
|
|
||||||
("\\(\\<[uU8]*R\"[^\\s-\\\\()]\\{0,16\\}(\\)" 1 font-lock-keyword-face t) ; start delimiter
|
|
||||||
( "\\<[uU8]*R\"[^\\s-\\\\()]\\{0,16\\}(\\(.*?\\))[^\\s-\\\\()]\\{0,16\\}\"" 1 font-lock-string-face t) ; actual string
|
|
||||||
( "\\<[uU8]*R\"[^\\s-\\\\()]\\{0,16\\}(.*?\\()[^\\s-\\\\()]\\{0,16\\}\"\\)" 1 font-lock-keyword-face t) ; end delimiter
|
|
||||||
) t))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|extra-fontify-c/c++ ()
|
|
||||||
(font-lock-add-keywords
|
|
||||||
nil '(;; PREPROCESSOR_CONSTANT, PREPROCESSORCONSTANT
|
|
||||||
("\\<[A-Z]*_[A-Z_]+\\>" . font-lock-constant-face)
|
|
||||||
("\\<[A-Z]\\{3,\\}\\>" . font-lock-constant-face)
|
|
||||||
;; integer/float/scientific numbers
|
|
||||||
("\\<\\([\\-+]*[0-9\\.]+\\)\\>" 1 font-lock-constant-face t)
|
|
||||||
("\\<\\([\\-+]*[0-9\\.]+\\)\\(f\\)\\>"
|
|
||||||
(1 font-lock-constant-face t)
|
|
||||||
(2 font-lock-keyword-face t))
|
|
||||||
("\\<\\([\\-+]*[0-9\\.]+\\)\\([eE]\\)\\([\\-+]?[0-9]+\\)\\>"
|
|
||||||
(1 font-lock-constant-face t)
|
|
||||||
(2 font-lock-keyword-face t)
|
|
||||||
(3 font-lock-constant-face t))
|
|
||||||
) t))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/append-semicolon ()
|
|
||||||
"Append a semicolon to the end of this (or each selected) non-empty line."
|
|
||||||
(interactive)
|
|
||||||
(let ((beg (if (evil-visual-state-p) evil-visual-beginning (line-beginning-position)))
|
|
||||||
(end (if (evil-visual-state-p) evil-visual-end (line-end-position))))
|
|
||||||
(save-excursion
|
|
||||||
(goto-char beg)
|
|
||||||
(while (< (point) end)
|
|
||||||
(let ((lend (save-excursion (evil-last-non-blank) (point))))
|
|
||||||
(goto-char (1+ lend))
|
|
||||||
(unless (or (eq (char-before) ?\;)
|
|
||||||
(= lend (line-beginning-position)))
|
|
||||||
(insert ";")))
|
|
||||||
(forward-line)))
|
|
||||||
(when (evil-visual-state-p)
|
|
||||||
(evil-normal-state))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/sp-point-is-template-p (id action context)
|
|
||||||
(and (sp-in-code-p id action context)
|
|
||||||
(sp-point-after-word-p id action context)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/sp-point-after-include-p (id action context)
|
|
||||||
(and (sp-in-code-p id action context)
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(looking-at-p "[ ]*#include[^<]+"))))
|
|
||||||
|
|
||||||
(provide 'defuns-cc)
|
|
||||||
;;; defuns-cc.el ends here
|
|
|
@ -1,224 +0,0 @@
|
||||||
;;; defuns-scss.el
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/css-toggle-inline-or-block ()
|
|
||||||
"Toggles between a SCSS multiline block and one-line block."
|
|
||||||
(interactive)
|
|
||||||
(save-excursion
|
|
||||||
(let* ((bounds (ignore-errors (evil-a-curly)))
|
|
||||||
beg end)
|
|
||||||
(unless bounds
|
|
||||||
(user-error "No block found"))
|
|
||||||
(setq beg (car bounds)
|
|
||||||
end (cadr bounds))
|
|
||||||
(if (= (line-number-at-pos beg) (line-number-at-pos end))
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (1+ beg)) (insert "\n")
|
|
||||||
(unless (string-match ";[\s\t]*}$" (buffer-substring-no-properties beg (1+ end)))
|
|
||||||
(goto-char end) (insert "\n"))
|
|
||||||
(replace-regexp ";[\s\t]*" ";\n" nil beg (1+ end))
|
|
||||||
(setq end (cadr (evil-a-curly)))
|
|
||||||
(evil-indent beg end)
|
|
||||||
(delete-trailing-whitespace beg end))
|
|
||||||
(goto-char beg)
|
|
||||||
(evil-join beg end)
|
|
||||||
(goto-char (1+ beg))
|
|
||||||
(just-one-space)
|
|
||||||
(goto-char (cadr (evil-inner-curly)))
|
|
||||||
(just-one-space)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defalias 'doom/sass-build 'doom/scss-build)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/scss-build ()
|
|
||||||
"Compile all sass/scss files in project"
|
|
||||||
(interactive)
|
|
||||||
(if (bound-and-true-p gulpjs-project-mode)
|
|
||||||
(let ((default-directory (doom/project-root)))
|
|
||||||
(compile "gulp sass"))
|
|
||||||
(let ((scss-dir (f-slash (or (f-traverse-upwards (lambda (d)
|
|
||||||
(string-match-p "/\\(\\(s[ca]\\|c\\)ss\\|styles\\)/?$" d))
|
|
||||||
default-directory)
|
|
||||||
default-directory))))
|
|
||||||
(compile (format "%s %s --update '%s':'%s'"
|
|
||||||
scss-sass-command
|
|
||||||
(mapconcat 'identity scss-sass-options " ")
|
|
||||||
scss-dir
|
|
||||||
(or scss-output-directory
|
|
||||||
(awhen (f-traverse-upwards (lambda (d)
|
|
||||||
(f-dir? (format "%s/css" d)))
|
|
||||||
default-directory)
|
|
||||||
(format "%s/css" it))
|
|
||||||
"."))))))
|
|
||||||
|
|
||||||
(defface doom/counsel-css-selector-depth-face-1
|
|
||||||
'((((class color) (background dark)) (:foreground "#ffff00"))
|
|
||||||
(((class color) (background light)) (:foreground "#0000ff"))
|
|
||||||
(t (:foreground "#ffff00")))
|
|
||||||
"Selector depth 1")
|
|
||||||
(defface doom/counsel-css-selector-depth-face-2
|
|
||||||
'((((class color) (background dark)) (:foreground "#ffdd00"))
|
|
||||||
(((class color) (background light)) (:foreground "#3300ff"))
|
|
||||||
(t (:foreground "#ffdd00")))
|
|
||||||
"Selector depth 2")
|
|
||||||
(defface doom/counsel-css-selector-depth-face-3
|
|
||||||
'((((class color) (background dark)) (:foreground "#ffbb00"))
|
|
||||||
(((class color) (background light)) (:foreground "#6600ff"))
|
|
||||||
(t (:foreground "#ffbb00")))
|
|
||||||
"Selector depth 3")
|
|
||||||
(defface doom/counsel-css-selector-depth-face-4
|
|
||||||
'((((class color) (background dark)) (:foreground "#ff9900"))
|
|
||||||
(((class color) (background light)) (:foreground "#9900ff"))
|
|
||||||
(t (:foreground "#ff9900")))
|
|
||||||
"Selector depth 4")
|
|
||||||
(defface doom/counsel-css-selector-depth-face-5
|
|
||||||
'((((class color) (background dark)) (:foreground "#ff7700"))
|
|
||||||
(((class color) (background light)) (:foreground "#cc00ff"))
|
|
||||||
(t (:foreground "#ff7700")))
|
|
||||||
"Selector depth 5")
|
|
||||||
(defface doom/counsel-css-selector-depth-face-6
|
|
||||||
'((((class color) (background dark)) (:foreground "#ff5500"))
|
|
||||||
(((class color) (background light)) (:foreground "#ff00ff"))
|
|
||||||
(t (:foreground "#ff5500")))
|
|
||||||
"Selector depth 6")
|
|
||||||
|
|
||||||
(cl-defun doom/counsel-css--open-brace-forward (&optional $bound)
|
|
||||||
"Move to next open brace, skip commented brace"
|
|
||||||
(interactive)
|
|
||||||
(let ($ret)
|
|
||||||
(setq $ret (re-search-forward "[^#]{" $bound t))
|
|
||||||
(unless $ret (cl-return-from doom/counsel-css--open-brace-forward nil))
|
|
||||||
(backward-char)
|
|
||||||
(if (doom/counsel-css--comment-p (point))
|
|
||||||
(doom/counsel-css--open-brace-forward $bound)
|
|
||||||
$ret)))
|
|
||||||
|
|
||||||
(defun doom/counsel-css--substr-last-string ($text $key)
|
|
||||||
"Return the tail of $text without $key strings"
|
|
||||||
(while (string-match $key $text)
|
|
||||||
(setq $text (substring $text (1+ (string-match $key $text)))))
|
|
||||||
$text)
|
|
||||||
|
|
||||||
(cl-defun doom/counsel-css--fetch-previous-line (&optional $prev $noexcursion)
|
|
||||||
"Return previous nth ($prev) line strings.
|
|
||||||
If $noexcursion is not-nil cursor doesn't move."
|
|
||||||
;; In compressed Css without this return, it takes long time
|
|
||||||
(if (eq 1 (line-number-at-pos))
|
|
||||||
(cl-return-from doom/counsel-css--fetch-previous-line ""))
|
|
||||||
(or $prev (setq $prev 1))
|
|
||||||
(if $noexcursion (setq $noexcursion (point)))
|
|
||||||
(move-beginning-of-line (- 1 $prev))
|
|
||||||
(let (($po (point)) $res)
|
|
||||||
(move-end-of-line 1)
|
|
||||||
(setq $res (buffer-substring-no-properties $po (point)))
|
|
||||||
(if $noexcursion (goto-char $noexcursion))
|
|
||||||
$res))
|
|
||||||
|
|
||||||
(defun doom/counsel-css--comment-p (&optional $pos)
|
|
||||||
(or $pos (setq $pos (point)))
|
|
||||||
(nth 4 (parse-partial-sexp (point-min) $pos)))
|
|
||||||
|
|
||||||
(cl-defun doom/counsel-css--extract-selector ()
|
|
||||||
"Return selector infomation at the point"
|
|
||||||
(let (($multi "") $s $po1 $po2 $po3 $str $commentp)
|
|
||||||
;; Collect multiple selector across previous lines
|
|
||||||
;; (i.e. "div, \n p, \n span {...}")
|
|
||||||
(save-excursion
|
|
||||||
(while (string-match ",[\s\t]*$"
|
|
||||||
(setq $s (doom/counsel-css--fetch-previous-line)))
|
|
||||||
;; Skip commented selector (i.e. " // .blue,")
|
|
||||||
(save-excursion
|
|
||||||
(move-beginning-of-line 1)
|
|
||||||
(setq $po3 (point))
|
|
||||||
(setq $commentp (doom/counsel-css--comment-p (search-forward ","))))
|
|
||||||
(unless $commentp
|
|
||||||
(setq $multi (format "%s %s" (string-trim $s) $multi)))))
|
|
||||||
;; Extract selector include one-line-nesting (i.e. "div { p {...} }")
|
|
||||||
(save-excursion
|
|
||||||
(skip-chars-backward "^{};\n")
|
|
||||||
(setq $po1 (point))
|
|
||||||
;; (setq $beg2 $po1)
|
|
||||||
(skip-chars-forward "^{")
|
|
||||||
(setq $po2 (point))
|
|
||||||
(setq $str (buffer-substring-no-properties $po1 $po2))
|
|
||||||
;; i.e. "div { .box { p" -> " p"
|
|
||||||
(setq $str (doom/counsel-css--substr-last-string $str "{\\|}"))
|
|
||||||
(setq $str (string-trim $str))
|
|
||||||
;; Return (selector-name . (selector-beginning-point . selector-end-point))
|
|
||||||
(if (equal $multi "")
|
|
||||||
(cons (format "%s" $str) (cons $po1 $po2))
|
|
||||||
(cons (format "%s %s" (string-trim $multi) $str)
|
|
||||||
(cons $po3 $po2))))))
|
|
||||||
|
|
||||||
(cl-defun doom/counsel-css--selector-next (&optional $bound)
|
|
||||||
"Return and goto next selector."
|
|
||||||
(unless (doom/counsel-css--open-brace-forward $bound)
|
|
||||||
(cl-return-from doom/counsel-css--selector-next nil))
|
|
||||||
(doom/counsel-css--extract-selector))
|
|
||||||
|
|
||||||
(defun doom/counsel-css--selector-to-hash (&optional no-line-numbers)
|
|
||||||
"Collect all selectors and make hash table"
|
|
||||||
(let ($selector $paren-beg $paren-end $hash $dep $max $sl
|
|
||||||
$selector-name $selector-beg $selector-end
|
|
||||||
$selector-line)
|
|
||||||
(setq $hash (make-hash-table :test 'equal))
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (setq $selector (doom/counsel-css--selector-next))
|
|
||||||
(setq $paren-beg (point))
|
|
||||||
(setq $paren-end (scan-sexps $paren-beg 1))
|
|
||||||
(setq $max (cons $paren-end $max))
|
|
||||||
(setq $max (mapcar (lambda ($p) (if (< $p $paren-beg) nil $p)) $max))
|
|
||||||
(setq $max (delq nil $max))
|
|
||||||
(setq $dep (length $max))
|
|
||||||
(setq $selector-name (car $selector))
|
|
||||||
(setq
|
|
||||||
$selector-name
|
|
||||||
(cl-case $dep
|
|
||||||
(1 (propertize $selector-name 'face 'doom/counsel-css-selector-depth-face-1))
|
|
||||||
(2 (propertize $selector-name 'face 'doom/counsel-css-selector-depth-face-2))
|
|
||||||
(3 (propertize $selector-name 'face 'doom/counsel-css-selector-depth-face-3))
|
|
||||||
(4 (propertize $selector-name 'face 'doom/counsel-css-selector-depth-face-4))
|
|
||||||
(5 (propertize $selector-name 'face 'doom/counsel-css-selector-depth-face-5))
|
|
||||||
(6 (propertize $selector-name 'face 'doom/counsel-css-selector-depth-face-6))))
|
|
||||||
(setq $selector-beg (cadr $selector))
|
|
||||||
(setq $selector-end (cddr $selector))
|
|
||||||
(setq $selector-line (line-number-at-pos $selector-beg))
|
|
||||||
(if (<= $dep (length $sl))
|
|
||||||
(cl-loop repeat (- (1+ (length $sl)) $dep) do (pop $sl)))
|
|
||||||
(setq $sl (cons $selector-name $sl))
|
|
||||||
(puthash
|
|
||||||
(if no-line-numbers
|
|
||||||
(mapconcat 'identity (reverse $sl) " ")
|
|
||||||
(format "%s: %s"
|
|
||||||
(propertize (number-to-string $selector-line)
|
|
||||||
'face 'font-lock-function-name-face)
|
|
||||||
(mapconcat 'identity (reverse $sl) " ")))
|
|
||||||
(list $paren-beg $paren-end $dep $selector-beg $selector-end $selector-line)
|
|
||||||
$hash)))
|
|
||||||
$hash))
|
|
||||||
|
|
||||||
(defun doom/counsel-css--imenu-create-index-function ()
|
|
||||||
(let (($hash (doom/counsel-css--selector-to-hash t)))
|
|
||||||
(cl-loop for $k being hash-key in $hash using (hash-values $v)
|
|
||||||
collect (cons $k $v))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|counsel-css-imenu-setup ()
|
|
||||||
(when (memq major-mode '(css-mode scss-mode less-css-mode))
|
|
||||||
(setq imenu-create-index-function 'doom/counsel-css--imenu-create-index-function)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/counsel-css ()
|
|
||||||
(interactive)
|
|
||||||
(require 'counsel)
|
|
||||||
(ivy-read "Selectors: "
|
|
||||||
(let (($hash (doom/counsel-css--selector-to-hash)))
|
|
||||||
(cl-loop for $k being hash-key in $hash using (hash-values $v)
|
|
||||||
collect (cons $k $v)))
|
|
||||||
:require-match t
|
|
||||||
:caller 'doom/counsel-css))
|
|
||||||
|
|
||||||
(provide 'defuns-scss)
|
|
||||||
;;; defuns-scss.el ends here
|
|
|
@ -1,63 +0,0 @@
|
||||||
;;; defuns-elisp.el
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:byte-compile "defuns-elisp" nil t)
|
|
||||||
(evil-define-command doom:byte-compile (&optional bang)
|
|
||||||
(interactive "<!>")
|
|
||||||
(if bang (doom-byte-compile) (byte-compile-file buffer-file-name)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/elisp-find-function-at-pt ()
|
|
||||||
(interactive)
|
|
||||||
(let ((func (function-called-at-point)))
|
|
||||||
(if func (find-function func))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/elisp-find-function-at-pt-other-window ()
|
|
||||||
(interactive)
|
|
||||||
(let ((func (function-called-at-point)))
|
|
||||||
(if func (find-function-other-window func))))
|
|
||||||
|
|
||||||
(defsubst doom--ert-pre ()
|
|
||||||
(save-buffer)
|
|
||||||
(eval-buffer))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/ert-run-test ()
|
|
||||||
(interactive)
|
|
||||||
(let (case-fold-search thing)
|
|
||||||
(doom--ert-pre)
|
|
||||||
(setq thing (thing-at-point 'defun t))
|
|
||||||
(if thing
|
|
||||||
(if (string-match "(ert-deftest \\([^ ]+\\)" thing)
|
|
||||||
(ert-run-tests-interactively
|
|
||||||
(substring thing (match-beginning 1) (match-end 1)))
|
|
||||||
(user-error "Invalid test at point"))
|
|
||||||
(user-error "No test found at point"))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/ert-rerun-test ()
|
|
||||||
(interactive)
|
|
||||||
(let (case-fold-search thing)
|
|
||||||
(doom--ert-pre)
|
|
||||||
(setq thing (car-safe ert--selector-history))
|
|
||||||
(if thing
|
|
||||||
(ert-run-tests-interactively thing)
|
|
||||||
(message "No test found in history, looking for test at point")
|
|
||||||
(doom/ert-run-test))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/ert-run-all-tests ()
|
|
||||||
(interactive)
|
|
||||||
(ert-delete-all-tests)
|
|
||||||
(doom--ert-pre)
|
|
||||||
(ert-run-tests-interactively t))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/elisp-inf-ielm ()
|
|
||||||
(ielm)
|
|
||||||
(let ((buf (current-buffer)))
|
|
||||||
(bury-buffer)
|
|
||||||
(pop-to-buffer buf)))
|
|
||||||
|
|
||||||
(provide 'defuns-elisp)
|
|
||||||
;;; defuns-elisp.el ends here
|
|
|
@ -1,140 +0,0 @@
|
||||||
;;; defuns-eshell.el
|
|
||||||
|
|
||||||
(require 'eshell)
|
|
||||||
|
|
||||||
(defvar doom-eshell-buffers '() "")
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|eshell-cleanup ()
|
|
||||||
(when (eq major-mode 'eshell-mode)
|
|
||||||
(setq doom-eshell-buffers (delete (current-buffer) doom-eshell-buffers))
|
|
||||||
(cond ((doom/popup-p)
|
|
||||||
(delete-window))
|
|
||||||
((string= "eshell" (wg-workgroup-name (wg-current-workgroup t)))
|
|
||||||
(if (one-window-p)
|
|
||||||
(doom:workgroup-delete)
|
|
||||||
(delete-window))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|eshell-init ()
|
|
||||||
(when (eq major-mode 'eshell-mode)
|
|
||||||
(add-to-list 'doom-eshell-buffers (current-buffer))))
|
|
||||||
|
|
||||||
(defun doom--eshell-outside-prompt-p (&optional offset)
|
|
||||||
(< (point) eshell-last-output-end))
|
|
||||||
|
|
||||||
(defun doom--eshell-current-git-branch ()
|
|
||||||
(let ((branch (car (loop for match in (split-string (shell-command-to-string "git branch") "\n")
|
|
||||||
when (string-match "^\*" match)
|
|
||||||
collect match))))
|
|
||||||
(if (not (eq branch nil))
|
|
||||||
(concat " [" (substring branch 2) "]")
|
|
||||||
"")))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-split ()
|
|
||||||
(interactive)
|
|
||||||
(select-window (split-window-vertically))
|
|
||||||
(doom:eshell))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-vsplit ()
|
|
||||||
(interactive)
|
|
||||||
(select-window (split-window-horizontally))
|
|
||||||
(doom:eshell))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-prompt ()
|
|
||||||
(concat (propertize (abbreviate-file-name (eshell/pwd)) 'face 'eshell-prompt)
|
|
||||||
(propertize (doom--eshell-current-git-branch) 'face 'font-lock-function-name-face)
|
|
||||||
(propertize " λ " 'face 'font-lock-constant-face)))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:eshell "defuns-eshell" nil t)
|
|
||||||
(evil-define-command doom:eshell (&optional bang)
|
|
||||||
"Create a shell in the current buffer. If BANG, use a popup buffer."
|
|
||||||
(interactive "<!>")
|
|
||||||
(let ((buf (if bang
|
|
||||||
(get-buffer-create "*eshell:popup*")
|
|
||||||
(generate-new-buffer eshell-buffer-name))))
|
|
||||||
(with-current-buffer buf
|
|
||||||
(unless (eq major-mode 'eshell-mode) (eshell-mode)))
|
|
||||||
(if bang
|
|
||||||
(doom/popup-buffer buf)
|
|
||||||
(pop-to-buffer-same-window buf))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-tab ()
|
|
||||||
"Create a separate tab for the shell."
|
|
||||||
(interactive)
|
|
||||||
(unless (wg-switch-to-workgroup (wg-get-workgroup "eshell" t) t)
|
|
||||||
(doom:tab-create nil "eshell"))
|
|
||||||
(let ((buf (--find (string-match-p "^\\*eshell" (buffer-name (window-buffer it)))
|
|
||||||
(doom/get-visible-windows))))
|
|
||||||
(if buf
|
|
||||||
(select-window (get-buffer-window buf))
|
|
||||||
(doom:eshell))
|
|
||||||
(doom/workgroup-display)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-frame ()
|
|
||||||
"Create a separate frame for the shell."
|
|
||||||
(interactive)
|
|
||||||
(doom/new-frame)
|
|
||||||
(doom:eshell))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-evil-append ()
|
|
||||||
(interactive)
|
|
||||||
(goto-char eshell-last-output-end)
|
|
||||||
(call-interactively 'evil-append-line))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-evil-append-maybe ()
|
|
||||||
(interactive)
|
|
||||||
(if (doom--eshell-outside-prompt-p)
|
|
||||||
(doom/eshell-evil-append)
|
|
||||||
(call-interactively 'evil-append)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-evil-prepend ()
|
|
||||||
(interactive)
|
|
||||||
(goto-char eshell-last-output-end)
|
|
||||||
(call-interactively 'evil-insert))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-evil-prepend-maybe ()
|
|
||||||
(interactive)
|
|
||||||
(if (doom--eshell-outside-prompt-p)
|
|
||||||
(doom/eshell-evil-prepend)
|
|
||||||
(call-interactively 'evil-insert)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-evil-replace-maybe ()
|
|
||||||
(interactive)
|
|
||||||
(if (doom--eshell-outside-prompt-p)
|
|
||||||
(user-error "Cannot edit read-only region")
|
|
||||||
(call-interactively 'evil-replace)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-evil-replace-state-maybe ()
|
|
||||||
(interactive)
|
|
||||||
(if (doom--eshell-outside-prompt-p)
|
|
||||||
(user-error "Cannot edit read-only region")
|
|
||||||
(call-interactively 'evil-replace-state)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-evil-change ()
|
|
||||||
(interactive)
|
|
||||||
(when (doom--eshell-outside-prompt-p)
|
|
||||||
(goto-char eshell-last-output-end))
|
|
||||||
(call-interactively 'evil-change))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/eshell-evil-change-line ()
|
|
||||||
(interactive)
|
|
||||||
(when (doom--eshell-outside-prompt-p)
|
|
||||||
(goto-char eshell-last-output-end))
|
|
||||||
(call-interactively 'evil-change-line))
|
|
||||||
|
|
||||||
(provide 'defuns-eshell)
|
|
||||||
;;; defuns-eshell.el ends here
|
|
|
@ -1,18 +0,0 @@
|
||||||
;;; defuns-go.el
|
|
||||||
|
|
||||||
;; TODO Implement doom:go-get-package
|
|
||||||
(defun doom--go-get-package ())
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom:go-test-run-all ()
|
|
||||||
(interactive)
|
|
||||||
(async-shell-command (format "cd '%s' && go test" (doom/project-root))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom:go-test-run-package ()
|
|
||||||
(interactive)
|
|
||||||
(error "Not yet implemented")
|
|
||||||
(async-shell-command (format "cd '%s' && go test %s" (doom/project-root) (doom--go-get-package))))
|
|
||||||
|
|
||||||
(provide 'defuns-go)
|
|
||||||
;;; defuns-go.el ends here
|
|
|
@ -1,35 +0,0 @@
|
||||||
;;; defuns-java.el
|
|
||||||
|
|
||||||
;; yasnippet defuns
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/java-android-mode-is-layout-file ()
|
|
||||||
(and android-mode
|
|
||||||
(eq major-mode 'nxml-mode)
|
|
||||||
(string-equal (file-name-base (directory-file-name default-directory)) "layout")))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/java-android-mode-in-tags (&rest tags)
|
|
||||||
(-contains? tags (android-mode-tag-name)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/java-android-mode-tag-name ()
|
|
||||||
(save-excursion
|
|
||||||
(let (beg end)
|
|
||||||
(nxml-backward-up-element)
|
|
||||||
(evil-forward-word-begin)
|
|
||||||
(setq beg (point))
|
|
||||||
(evil-forward-WORD-end)
|
|
||||||
(setq end (1+ (point)))
|
|
||||||
(buffer-substring-no-properties beg end))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|android-mode-enable-maybe ()
|
|
||||||
(let ((root (doom/project-root)))
|
|
||||||
(when (or (doom/project-has-files "local.properties" root)
|
|
||||||
(doom/project-has-files "AndroidManifest.xml" root)
|
|
||||||
(doom/project-has-files "src/main/AndroidManifest.xml" root))
|
|
||||||
(android-mode +1)
|
|
||||||
(doom/set-build-command "./gradlew %s" "build.gradle"))))
|
|
||||||
|
|
||||||
(provide 'defuns-java)
|
|
||||||
;;; defuns-java.el ends here
|
|
|
@ -1,15 +0,0 @@
|
||||||
;;; defuns-julia.el
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/julia-repl ()
|
|
||||||
"Run an inferior instance of `julia' inside Emacs."
|
|
||||||
(interactive)
|
|
||||||
(let ((buffer (get-buffer-create "*Julia*")))
|
|
||||||
(unless (comint-check-proc "*Julia*")
|
|
||||||
(apply #'make-comint-in-buffer "Julia" "*Julia*" julia-program julia-arguments))
|
|
||||||
(pop-to-buffer buffer)
|
|
||||||
(with-current-buffer buffer
|
|
||||||
(inferior-julia-mode))))
|
|
||||||
|
|
||||||
(provide 'defuns-julia)
|
|
||||||
;;; defuns-julia.el ends here
|
|
|
@ -1,10 +0,0 @@
|
||||||
;;; defuns-lua.el
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/inf-lua ()
|
|
||||||
(interactive)
|
|
||||||
(lua-start-process "lua" "lua")
|
|
||||||
(pop-to-buffer lua-process-buffer))
|
|
||||||
|
|
||||||
(provide 'defuns-lua)
|
|
||||||
;;; defuns-lua.el ends here
|
|
|
@ -1,24 +0,0 @@
|
||||||
;;; defuns-markdown.el
|
|
||||||
|
|
||||||
;; Implement strike-through formatting
|
|
||||||
(defvar doom--markdown-regex-del
|
|
||||||
"\\(^\\|[^\\]\\)\\(\\(~\\{2\\}\\)\\([^ \n \\]\\|[^ \n ]\\(?:.\\|\n[^\n]\\)*?[^\\ ]\\)\\(\\3\\)\\)")
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/markdown-insert-del ()
|
|
||||||
"Surround region in github strike-through delimiters."
|
|
||||||
(interactive)
|
|
||||||
(let ((delim "~~"))
|
|
||||||
(if (markdown-use-region-p)
|
|
||||||
;; Active region
|
|
||||||
(let ((bounds (markdown-unwrap-things-in-region
|
|
||||||
(region-beginning) (region-end)
|
|
||||||
doom--markdown-regex-del 2 4)))
|
|
||||||
(markdown-wrap-or-insert delim delim nil (car bounds) (cdr bounds)))
|
|
||||||
;; Bold markup removal, bold word at point, or empty markup insertion
|
|
||||||
(if (thing-at-point-looking-at doom--markdown-regex-del)
|
|
||||||
(markdown-unwrap-thing-at-point nil 2 4)
|
|
||||||
(markdown-wrap-or-insert delim delim 'word nil nil)))))
|
|
||||||
|
|
||||||
(provide 'defuns-markdown)
|
|
||||||
;;; defuns-markdown.el ends here
|
|
|
@ -1,415 +0,0 @@
|
||||||
;;; defuns-org.el
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-indent ()
|
|
||||||
"Indent the current item (header or item). Otherwise, forward to
|
|
||||||
`self-insert-command'."
|
|
||||||
(interactive)
|
|
||||||
(cond ((org-at-item-p)
|
|
||||||
(org-indent-item-tree))
|
|
||||||
((org-at-heading-p)
|
|
||||||
(ignore-errors (org-demote)))
|
|
||||||
(t (call-interactively 'self-insert-command))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-indent-or-next-field ()
|
|
||||||
"Depending on the context either indent the current item or go the next table field."
|
|
||||||
(interactive)
|
|
||||||
(call-interactively (if (org-at-table-p) 'org-table-next-field 'doom/org-indent)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-dedent ()
|
|
||||||
"Dedent the current item (header or item). Otherwise, forward to
|
|
||||||
`self-insert-command'."
|
|
||||||
(interactive)
|
|
||||||
(cond ((org-at-item-p)
|
|
||||||
(let ((struct (if (org-region-active-p)
|
|
||||||
(save-excursion (goto-char (region-beginning))
|
|
||||||
(org-list-struct))
|
|
||||||
(org-list-struct))))
|
|
||||||
(org-list-indent-item-generic -1 nil struct)))
|
|
||||||
((org-at-heading-p)
|
|
||||||
(ignore-errors (org-promote)))
|
|
||||||
(t (call-interactively 'self-insert-command))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-dedent-or-prev-field ()
|
|
||||||
"Depending on the context either dedent the current item or go the previous
|
|
||||||
table field."
|
|
||||||
(interactive)
|
|
||||||
(call-interactively (if (org-at-table-p) 'org-table-previous-field 'doom/org-dedent)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-insert-item (direction)
|
|
||||||
"Inserts a new heading, table cell or item, depending on the context.
|
|
||||||
DIRECTION can be 'above or 'below.
|
|
||||||
|
|
||||||
I use this instead of `org-insert-item' or `org-insert-heading' which are too
|
|
||||||
opinionated and perform this simple task incorrectly (e.g. whitespace in the
|
|
||||||
wrong places)."
|
|
||||||
(interactive)
|
|
||||||
(let* ((context (org-element-lineage
|
|
||||||
(org-element-context)
|
|
||||||
'(table table-row headline inlinetask item plain-list)
|
|
||||||
t))
|
|
||||||
(type (org-element-type context)))
|
|
||||||
(cond ((eq type 'item)
|
|
||||||
(let ((marker (org-element-property :bullet context)))
|
|
||||||
(cl-case direction
|
|
||||||
('below
|
|
||||||
(goto-char (line-end-position))
|
|
||||||
(insert (concat "\n" marker)))
|
|
||||||
('above
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(insert marker)
|
|
||||||
(save-excursion (insert "\n")))))
|
|
||||||
(when (org-element-property :checkbox context)
|
|
||||||
(insert "[ ] ")))
|
|
||||||
((memq type '(table table-row))
|
|
||||||
(cl-case direction
|
|
||||||
('below (org-table-insert-row t))
|
|
||||||
('above (doom/org-table-prepend-row-or-shift-up))))
|
|
||||||
(t
|
|
||||||
(let ((level (save-excursion
|
|
||||||
(org-back-to-heading)
|
|
||||||
(org-element-property
|
|
||||||
:level (org-element-lineage (org-element-context)
|
|
||||||
'(headline) t)))))
|
|
||||||
(cl-case direction
|
|
||||||
('below
|
|
||||||
(let ((at-eol (= (point) (1- (line-end-position)))))
|
|
||||||
(goto-char (line-end-position))
|
|
||||||
(org-end-of-subtree)
|
|
||||||
(insert (concat "\n"
|
|
||||||
(when (= level 1)
|
|
||||||
(if at-eol
|
|
||||||
(ignore (cl-incf level))
|
|
||||||
"\n"))
|
|
||||||
(make-string level ?*)
|
|
||||||
" "))))
|
|
||||||
('above
|
|
||||||
(org-back-to-heading)
|
|
||||||
(org-insert-heading)
|
|
||||||
(when (= level 1)
|
|
||||||
(save-excursion (evil-open-above 1))
|
|
||||||
(save-excursion (insert "\n")))))
|
|
||||||
(when (org-element-property :todo-type context)
|
|
||||||
(org-todo 'todo)))))
|
|
||||||
(evil-append-line 1)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-toggle-checkbox ()
|
|
||||||
(interactive)
|
|
||||||
(let ((context (org-element-lineage (org-element-context) '(item) t)))
|
|
||||||
(when context
|
|
||||||
(org-end-of-line)
|
|
||||||
(org-beginning-of-line)
|
|
||||||
(if (org-element-property :checkbox context)
|
|
||||||
(when (search-backward-regexp "\\[[ +-]\\]" (line-beginning-position) t)
|
|
||||||
(delete-char 4))
|
|
||||||
(insert "[ ] ")))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-toggle-fold ()
|
|
||||||
"Toggle the local fold at the point (as opposed to cycling through all levels
|
|
||||||
with `org-cycle')."
|
|
||||||
(interactive)
|
|
||||||
(cond ((org-at-heading-p)
|
|
||||||
(outline-toggle-children))
|
|
||||||
((org-at-item-p)
|
|
||||||
(org-cycle))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-dwim-at-point ()
|
|
||||||
"Do-what-I-mean at point. This includes following timestamp links, aligning
|
|
||||||
tables, toggling checkboxes/todos, executing babel blocks, previewing latex
|
|
||||||
fragments, opening links, or refreshing images."
|
|
||||||
(interactive)
|
|
||||||
(let* ((scroll-pt (window-start))
|
|
||||||
(context (org-element-context))
|
|
||||||
(type (org-element-type context))
|
|
||||||
(value (org-element-property :value context)))
|
|
||||||
(cond
|
|
||||||
((memq type '(planning timestamp))
|
|
||||||
(org-follow-timestamp-link))
|
|
||||||
|
|
||||||
((memq type '(table table-row))
|
|
||||||
(if (org-element-property :tblfm (org-element-property :parent context))
|
|
||||||
(org-table-recalculate t)
|
|
||||||
(org-table-align)))
|
|
||||||
|
|
||||||
((and (memq type '(item))
|
|
||||||
(org-element-property :checkbox context))
|
|
||||||
(org-toggle-checkbox))
|
|
||||||
|
|
||||||
((and (memq type '(headline))
|
|
||||||
(org-element-property :todo-type context))
|
|
||||||
(org-todo
|
|
||||||
(if (eq (org-element-property :todo-type context) 'done) 'todo 'done)))
|
|
||||||
|
|
||||||
((and (memq type '(headline))
|
|
||||||
(string= "ARCHIVE" (car-safe (org-get-tags))))
|
|
||||||
(org-force-cycle-archived))
|
|
||||||
|
|
||||||
((memq type '(headline))
|
|
||||||
(org-remove-latex-fragment-image-overlays)
|
|
||||||
(org-preview-latex-fragment '(4)))
|
|
||||||
|
|
||||||
((memq type '(babel-call))
|
|
||||||
(org-babel-lob-execute-maybe))
|
|
||||||
|
|
||||||
((memq type '(src-block inline-src-block))
|
|
||||||
(org-babel-execute-src-block))
|
|
||||||
|
|
||||||
((memq type '(latex-fragment latex-environment))
|
|
||||||
(org-preview-latex-fragment))
|
|
||||||
|
|
||||||
((memq type '(link))
|
|
||||||
(let ((path (org-element-property :path (org-element-lineage (org-element-context) '(link) t))))
|
|
||||||
(if (and path (image-type-from-file-name path))
|
|
||||||
(doom/org-refresh-inline-images)
|
|
||||||
(org-open-at-point))))
|
|
||||||
|
|
||||||
(t (doom/org-refresh-inline-images)))
|
|
||||||
(set-window-start nil scroll-pt)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-refresh-inline-images ()
|
|
||||||
"Refresh image previews in the current heading/tree."
|
|
||||||
(interactive)
|
|
||||||
(if (> (length org-inline-image-overlays) 0)
|
|
||||||
(org-remove-inline-images)
|
|
||||||
(org-display-inline-images
|
|
||||||
t t
|
|
||||||
(if (org-before-first-heading-p)
|
|
||||||
(line-beginning-position)
|
|
||||||
(save-excursion (org-back-to-heading) (point)))
|
|
||||||
(if (org-before-first-heading-p)
|
|
||||||
(line-end-position)
|
|
||||||
(save-excursion (org-end-of-subtree) (point))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-surround (delim)
|
|
||||||
"Surround the cursor (or selected region) with DELIM."
|
|
||||||
(if (region-active-p)
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (region-beginning))
|
|
||||||
(insert delim)
|
|
||||||
(goto-char (region-end))
|
|
||||||
(insert delim))
|
|
||||||
(insert delim)
|
|
||||||
(save-excursion (insert delim))))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
|
||||||
;; tables
|
|
||||||
;;
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-table-next-row ()
|
|
||||||
(interactive)
|
|
||||||
(if (org-at-table-p) (org-table-next-row) (org-down-element)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-table-previous-row ()
|
|
||||||
"Go to the previous row (same column) in the current table. Before doing so,
|
|
||||||
re-align the table if necessary. (Necessary because org-mode has a
|
|
||||||
`org-table-next-row', but not `org-table-previous-row')"
|
|
||||||
(interactive)
|
|
||||||
(if (org-at-table-p)
|
|
||||||
(progn
|
|
||||||
(org-table-maybe-eval-formula)
|
|
||||||
(org-table-maybe-recalculate-line)
|
|
||||||
(if (and org-table-automatic-realign
|
|
||||||
org-table-may-need-update)
|
|
||||||
(org-table-align))
|
|
||||||
(let ((col (org-table-current-column)))
|
|
||||||
(beginning-of-line 0)
|
|
||||||
(when (or (not (org-at-table-p)) (org-at-table-hline-p))
|
|
||||||
(beginning-of-line))
|
|
||||||
(org-table-goto-column col)
|
|
||||||
(skip-chars-backward "^|\n\r")
|
|
||||||
(when (org-looking-at-p " ") (forward-char))))
|
|
||||||
(org-up-element)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-table-next-field ()
|
|
||||||
(interactive)
|
|
||||||
(if (org-at-table-p) (org-table-next-field) (org-end-of-line)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-table-previous-field ()
|
|
||||||
(interactive)
|
|
||||||
(if (org-at-table-p) (org-table-previous-field) (org-beginning-of-line)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-table-append-field-or-shift-right ()
|
|
||||||
(interactive)
|
|
||||||
(org-shiftmetaright)
|
|
||||||
(when (org-at-table-p) (org-metaright)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-table-prepend-field-or-shift-left ()
|
|
||||||
(interactive)
|
|
||||||
(if (org-at-table-p) (org-shiftmetaright) (org-shiftmetaleft)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-table-append-row-or-shift-down ()
|
|
||||||
(interactive)
|
|
||||||
(org-shiftmetadown)
|
|
||||||
(when (org-at-table-p) (org-metadown)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-table-prepend-row-or-shift-up ()
|
|
||||||
(interactive)
|
|
||||||
(if (org-at-table-p)
|
|
||||||
(org-shiftmetadown)
|
|
||||||
(org-shiftmetaup)))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
|
||||||
;; Links
|
|
||||||
;;
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:org-link "defuns-org" nil t)
|
|
||||||
(evil-define-command doom:org-link (link)
|
|
||||||
"Add LINK to the org buffer. If a selection is active, link selection to LINK."
|
|
||||||
(interactive "<a>")
|
|
||||||
(unless (eq major-mode 'org-mode)
|
|
||||||
(user-error "Not in an org-mode buffer"))
|
|
||||||
(let ((beg evil-visual-beginning)
|
|
||||||
(end evil-visual-end))
|
|
||||||
(org-insert-link nil link (when (and beg end) (buffer-substring-no-properties beg end)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-remove-link ()
|
|
||||||
"Replace an org link by its description or if empty its address"
|
|
||||||
(interactive)
|
|
||||||
(if (org-in-regexp org-bracket-link-regexp 1)
|
|
||||||
(let ((remove (list (match-beginning 0) (match-end 0)))
|
|
||||||
(description (if (match-end 3)
|
|
||||||
(org-match-string-no-properties 3)
|
|
||||||
(org-match-string-no-properties 1))))
|
|
||||||
(apply 'delete-region remove)
|
|
||||||
(insert description))))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
|
||||||
;; org-capture
|
|
||||||
;;
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-capture (&optional template string)
|
|
||||||
"Run `org-capture' in a new, disposable popup frame."
|
|
||||||
(interactive)
|
|
||||||
(let ((org-capture-entry (org-capture-select-template template)))
|
|
||||||
(cond ((equal org-capture-entry "C")
|
|
||||||
(find-file (expand-file-name "module-org-notes.el" doom-modules-dir))
|
|
||||||
(re-search-forward "^\\s-+(setq org-capture-templates" (point-max) t)
|
|
||||||
(recenter))
|
|
||||||
((not (equal org-capture-entry "q"))
|
|
||||||
(let ((frame (make-frame '((name . "org-capture") (height . 15) (width . 80)))))
|
|
||||||
(with-selected-frame frame
|
|
||||||
(if string
|
|
||||||
(org-capture-string string)
|
|
||||||
(org-capture))))))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:org-capture "defuns-org" nil t)
|
|
||||||
(evil-define-operator doom:org-capture (&optional beg end bang)
|
|
||||||
"Send a selection to `doom/org-capture'."
|
|
||||||
:move-point nil
|
|
||||||
:type inclusive
|
|
||||||
(interactive "<r><!>")
|
|
||||||
(doom/org-capture
|
|
||||||
(if (and (evil-visual-state-p) beg end)
|
|
||||||
(buffer-substring beg end)
|
|
||||||
"")))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
|
||||||
;; attachments
|
|
||||||
;;
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:org-attach "defuns-org-notes" nil t)
|
|
||||||
(evil-define-command doom:org-attach (&optional uri)
|
|
||||||
(interactive "<a>")
|
|
||||||
(unless (eq major-mode 'org-mode)
|
|
||||||
(user-error "Not in an org-mode buffer"))
|
|
||||||
(if uri
|
|
||||||
(let* ((rel-path (org-download--fullname uri))
|
|
||||||
(new-path (f-expand rel-path))
|
|
||||||
(image-p (image-type-from-file-name uri)))
|
|
||||||
(cond ((string-match-p (concat "^" (regexp-opt '("http" "https" "nfs" "ftp" "file")) ":/") uri)
|
|
||||||
(url-copy-file uri new-path))
|
|
||||||
(t (copy-file uri new-path)))
|
|
||||||
(unless new-path
|
|
||||||
(user-error "No file was provided"))
|
|
||||||
(if (evil-visual-state-p)
|
|
||||||
(org-insert-link nil (format "./%s" rel-path)
|
|
||||||
(concat (buffer-substring-no-properties (region-beginning) (region-end))
|
|
||||||
" " (doom--org-attach-icon rel-path)))
|
|
||||||
|
|
||||||
(insert (if image-p
|
|
||||||
(format "[[./%s]] " rel-path)
|
|
||||||
(format "%s [[./%s][%s]] "
|
|
||||||
(doom--org-attach-icon rel-path)
|
|
||||||
rel-path (f-filename rel-path)))))
|
|
||||||
(when (string-match-p (regexp-opt '("jpg" "jpeg" "gif" "png")) (f-ext rel-path))
|
|
||||||
(org-redisplay-inline-images)))
|
|
||||||
(let ((default-directory ".attach/"))
|
|
||||||
(if (file-exists-p default-directory)
|
|
||||||
(call-interactively 'find-file)
|
|
||||||
(user-error "No attachments")))))
|
|
||||||
|
|
||||||
(defun doom--org-attach-icon (path)
|
|
||||||
(char-to-string (pcase (downcase (f-ext path))
|
|
||||||
("jpg" ?) ("jpeg" ?) ("png" ?) ("gif" ?)
|
|
||||||
("pdf" ?)
|
|
||||||
("ppt" ?) ("pptx" ?)
|
|
||||||
("xls" ?) ("xlsx" ?)
|
|
||||||
("doc" ?) ("docx" ?)
|
|
||||||
("ogg" ?) ("mp3" ?) ("wav" ?)
|
|
||||||
("mp4" ?) ("mov" ?) ("avi" ?)
|
|
||||||
("zip" ?) ("gz" ?) ("tar" ?) ("7z" ?) ("rar" ?)
|
|
||||||
(_ ?))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-cleanup-attachments ()
|
|
||||||
;; "Deletes any attachments that are no longer present in the org-mode buffer."
|
|
||||||
(let* ((attachments-local (doom-org-attachments))
|
|
||||||
(attachments (f-entries org-attach-directory))
|
|
||||||
(to-delete (-difference attachments-local attachments)))
|
|
||||||
;; TODO
|
|
||||||
to-delete))
|
|
||||||
|
|
||||||
(defun doom-org-attachments ()
|
|
||||||
(unless (eq major-mode 'org-mode)
|
|
||||||
(user-error "Not an org buffer"))
|
|
||||||
(org-save-outline-visibility nil
|
|
||||||
(let ((attachments '())
|
|
||||||
element
|
|
||||||
file)
|
|
||||||
(when (and (f-dir? org-attach-directory)
|
|
||||||
(> (length (f-glob (concat (f-slash org-attach-directory) "*"))) 0))
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (progn (org-next-link) (not org-link-search-failed))
|
|
||||||
(setq element (org-element-lineage (org-element-context) '(link) t))
|
|
||||||
(when element
|
|
||||||
(setq file (expand-file-name (org-element-property :path element)))
|
|
||||||
(when (and (string= (org-element-property :type element) "file")
|
|
||||||
(string= (concat (f-base (f-dirname file)) "/") org-attach-directory)
|
|
||||||
(file-exists-p file))
|
|
||||||
(push file attachments))))))
|
|
||||||
(-distinct attachments))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/org-download-dnd (uri action)
|
|
||||||
(if (eq major-mode 'org-mode)
|
|
||||||
(doom:org-attach uri)
|
|
||||||
(let ((dnd-protocol-alist
|
|
||||||
(rassq-delete-all 'doom/org-download-dnd (copy-alist dnd-protocol-alist))))
|
|
||||||
(dnd-handle-one-url nil action uri))))
|
|
||||||
|
|
||||||
(provide 'defuns-org)
|
|
||||||
;;; defuns-org.el ends here
|
|
|
@ -1,15 +0,0 @@
|
||||||
;;; defuns-python.el
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom*anaconda-mode-doc-buffer ()
|
|
||||||
"Delete the window on escape or C-g."
|
|
||||||
(with-current-buffer (get-buffer "*anaconda-doc*")
|
|
||||||
(local-set-key [escape] 'anaconda-nav-quit)
|
|
||||||
(local-set-key [?\C-g] 'anaconda-nav-quit)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/inf-python ()
|
|
||||||
(run-python python-shell-interpreter t t))
|
|
||||||
|
|
||||||
(provide 'defuns-python)
|
|
||||||
;;; defuns-python.el ends here
|
|
|
@ -1,97 +0,0 @@
|
||||||
;;; defuns-quickrun.el
|
|
||||||
|
|
||||||
;;;; Code building ;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;###autoload
|
|
||||||
(defvar doom--build-command '("make %s" . "Makefile"))
|
|
||||||
(make-variable-buffer-local 'doom--build-command)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/set-build-command (command &optional file)
|
|
||||||
(when (or (null file)
|
|
||||||
(doom/project-has-files file))
|
|
||||||
(setq doom--build-command `(,command . ,file))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:build "defuns-quickrun" nil t)
|
|
||||||
(evil-define-command doom:build (arg)
|
|
||||||
"Call a build command in the current directory. If ARG is nil this function calls
|
|
||||||
`recompile', otherwise it calls `compile' passing ARG as build command."
|
|
||||||
(interactive "<sh>")
|
|
||||||
(when (null doom--build-command)
|
|
||||||
(user-error "No build command was set"))
|
|
||||||
(let ((build-file (cdr doom--build-command))
|
|
||||||
(build-cmd (car doom--build-command))
|
|
||||||
(project-dir (doom/project-root)))
|
|
||||||
(if (or (null build-file) (f-exists? (f-expand build-file project-dir)))
|
|
||||||
(if (or (symbolp build-cmd) (functionp build-cmd))
|
|
||||||
(if (commandp build-cmd)
|
|
||||||
(call-interactively build-cmd)
|
|
||||||
(funcall build-cmd))
|
|
||||||
(let ((default-directory project-dir))
|
|
||||||
(compile (format build-cmd (or arg "")))))
|
|
||||||
(error "Could not build!"))))
|
|
||||||
|
|
||||||
;;;; Code running ;;;;;;;;;;;;;;;;;;;;;;
|
|
||||||
;;;###autoload (autoload 'doom:eval-buffer "defuns-quickrun" nil t)
|
|
||||||
(evil-define-command doom:eval-buffer ()
|
|
||||||
"Evaluate the whole buffer."
|
|
||||||
:move-point nil :repeat nil
|
|
||||||
(interactive)
|
|
||||||
(cond ((eq major-mode 'emacs-lisp-mode)
|
|
||||||
(doom:eval-region (point-min) (point-max)))
|
|
||||||
(t (quickrun))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:eval-region "defuns-quickrun" nil t)
|
|
||||||
(evil-define-operator doom:eval-region (beg end)
|
|
||||||
"Evaluate a region and, if large enough, prints its output to a popup buffer (if an
|
|
||||||
elisp buffer). Otherwise forward the region to Quickrun."
|
|
||||||
:move-point nil :repeat nil
|
|
||||||
(interactive "<r>")
|
|
||||||
(cond ((eq major-mode 'emacs-lisp-mode)
|
|
||||||
(require 'pp)
|
|
||||||
(let ((result (eval (read (buffer-substring-no-properties beg end))))
|
|
||||||
lines)
|
|
||||||
(let ((buf (get-buffer-create "*eval*")))
|
|
||||||
(with-current-buffer buf
|
|
||||||
(read-only-mode -1)
|
|
||||||
(setq-local scroll-margin 0)
|
|
||||||
(erase-buffer)
|
|
||||||
(prin1 result buf)
|
|
||||||
(emacs-lisp-mode)
|
|
||||||
(pp-buffer)
|
|
||||||
(read-only-mode 1)
|
|
||||||
(setq lines (count-lines (point-min) (point-max)))
|
|
||||||
(goto-char (point-min))
|
|
||||||
(when (< lines 5)
|
|
||||||
(message "%s" (buffer-substring (point-min) (point-max)))
|
|
||||||
(kill-buffer buf)))
|
|
||||||
(unless (< lines 5)
|
|
||||||
(doom/popup-buffer buf)))))
|
|
||||||
(t (quickrun-region beg end))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:eval-region-and-replace "defuns-quickrun" nil t)
|
|
||||||
(evil-define-operator doom:eval-region-and-replace (beg end)
|
|
||||||
(interactive "<r>")
|
|
||||||
(cond ((eq major-mode 'emacs-lisp-mode)
|
|
||||||
(kill-region beg end)
|
|
||||||
(condition-case nil
|
|
||||||
(prin1 (eval (read (current-kill 0)))
|
|
||||||
(current-buffer))
|
|
||||||
(error (message "Invalid expression")
|
|
||||||
(insert (current-kill 0)))))
|
|
||||||
(t (quickrun-replace-region beg end))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom*quickrun-close-popup (&optional _ _ _ _)
|
|
||||||
"Allows us to re-run quickrun from inside the quickrun buffer."
|
|
||||||
(awhen (get-buffer-window quickrun/buffer-name)
|
|
||||||
(shut-up! (quickrun/kill-running-process))
|
|
||||||
(doom/popup-close it nil)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|quickrun-after-run ()
|
|
||||||
"Ensures window is scrolled to BOF"
|
|
||||||
(with-selected-window (get-buffer-window quickrun/buffer-name)
|
|
||||||
(goto-char (point-min))))
|
|
||||||
|
|
||||||
(provide 'defuns-quickrun)
|
|
||||||
;;; defuns-quickrun.el ends here
|
|
|
@ -1,73 +0,0 @@
|
||||||
;;; defuns-realgud.el
|
|
||||||
|
|
||||||
;; TODO Find a more elegant solution
|
|
||||||
;; FIXME Causes realgud:cmd-* to focus popup on every invocation
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom*realgud:run-process (debugger-name script-filename cmd-args minibuffer-history &optional no-reset)
|
|
||||||
(let ((cmd-buf))
|
|
||||||
(setq cmd-buf
|
|
||||||
(apply 'realgud-exec-shell debugger-name script-filename
|
|
||||||
(car cmd-args) no-reset (cdr cmd-args)))
|
|
||||||
(let ((process (get-buffer-process cmd-buf)))
|
|
||||||
(if (and process (eq 'run (process-status process)))
|
|
||||||
(progn
|
|
||||||
(pop-to-buffer cmd-buf)
|
|
||||||
(define-key evil-emacs-state-local-map (kbd "ESC ESC") 'doom/debug-quit)
|
|
||||||
(realgud:track-set-debugger debugger-name)
|
|
||||||
(realgud-cmdbuf-info-in-debugger?= 't)
|
|
||||||
(realgud-cmdbuf-info-cmd-args= cmd-args)
|
|
||||||
(when cmd-buf
|
|
||||||
(switch-to-buffer cmd-buf)
|
|
||||||
(when realgud-cmdbuf-info
|
|
||||||
(let* ((info realgud-cmdbuf-info)
|
|
||||||
(cmd-args (realgud-cmdbuf-info-cmd-args info))
|
|
||||||
(cmd-str (mapconcat 'identity cmd-args " ")))
|
|
||||||
(set minibuffer-history
|
|
||||||
(list-utils-uniq (cons cmd-str (eval minibuffer-history))))))))
|
|
||||||
;; else
|
|
||||||
(progn
|
|
||||||
(if cmd-buf (switch-to-buffer cmd-buf))
|
|
||||||
(message "Error running command: %s" (mapconcat 'identity cmd-args " ")))))
|
|
||||||
cmd-buf))
|
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:debug-toggle-breakpoint "defuns-realgud" nil t)
|
|
||||||
(evil-define-command doom:debug-toggle-breakpoint (&optional bang)
|
|
||||||
(interactive "<!>")
|
|
||||||
(call-interactively (if bang 'realgud:cmd-clear 'realgud:cmd-break)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/debug-quit ()
|
|
||||||
(interactive)
|
|
||||||
(ignore-errors (call-interactively 'realgud:cmd-quit))
|
|
||||||
(doom/popup-close)
|
|
||||||
(evil-normal-state))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:debug "defuns-realgud" nil t)
|
|
||||||
(evil-define-command doom:debug (&optional path)
|
|
||||||
"Initiate debugger for current major mode"
|
|
||||||
(interactive "<f>")
|
|
||||||
(let ((default-directory (doom/project-root)))
|
|
||||||
(cond ((memq major-mode '(c-mode c++-mode))
|
|
||||||
(realgud:gdb (if path (concat "gdb " path))))
|
|
||||||
((memq major-mode '(ruby-mode enh-ruby-mode))
|
|
||||||
(doom:repl nil (format "run '%s'" (f-filename (or path buffer-file-name)))))
|
|
||||||
((eq major-mode 'sh-mode)
|
|
||||||
(let ((shell sh-shell))
|
|
||||||
(when (string= shell "sh")
|
|
||||||
(setq shell "bash"))
|
|
||||||
(cond ((string= shell "bash")
|
|
||||||
(realgud:bashdb (if path (concat "bashdb " path))))
|
|
||||||
((string= shell "zsh")
|
|
||||||
(realgud:zshdb (if path (concat "zshdb " path))))
|
|
||||||
(t (user-error "No shell debugger for %s" shell)))))
|
|
||||||
;; TODO Add python debugging
|
|
||||||
((memq major-mode '(js-mode js2-mode js3-mode))
|
|
||||||
(realgud:trepanjs))
|
|
||||||
((eq major-mode 'haskell-mode)
|
|
||||||
(haskell-debug))
|
|
||||||
(t (user-error "No debugger for %s" major-mode)))))
|
|
||||||
|
|
||||||
|
|
||||||
(provide 'defuns-realgud)
|
|
||||||
;;; defuns-realgud.el ends here
|
|
|
@ -1,40 +0,0 @@
|
||||||
;;; defuns-regex.el
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|reb-cleanup ()
|
|
||||||
(replace-regexp "^[ \n]*" "" nil (point-min) (point-max))
|
|
||||||
(text-scale-set 2)
|
|
||||||
(goto-char 2))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:regex "defuns-regex" nil t)
|
|
||||||
(evil-define-operator doom:regex (beg end type &optional regexstr bang)
|
|
||||||
"Either a) converts selected (or entered-in) pcre regex into elisp
|
|
||||||
regex, OR b) opens up re-builder."
|
|
||||||
:move-point nil
|
|
||||||
:type inclusive
|
|
||||||
:repeat nil
|
|
||||||
(interactive "<R><a><!>")
|
|
||||||
(if (reb-mode-buffer-p)
|
|
||||||
(if regexstr
|
|
||||||
(let ((regexstr (s-trim (buffer-string))))
|
|
||||||
(if bang
|
|
||||||
(rxt-explain-pcre regexstr)
|
|
||||||
(rxt-pcre-to-elisp (s-trim (buffer-string)))))
|
|
||||||
(erase-buffer)
|
|
||||||
(insert (concat "/" regexstr "/")))
|
|
||||||
(cond ((and beg end (/= beg (1- end))) ; Convert selection from pcre regex to elisp
|
|
||||||
(let ((regexstr (buffer-substring-no-properties beg end)))
|
|
||||||
(if bang
|
|
||||||
(rxt-explain-pcre (concat "/" regexstr "/"))
|
|
||||||
(delete-region beg end)
|
|
||||||
(insert (rxt-pcre-to-elisp regexstr)))))
|
|
||||||
(regexstr ; Convert input regex into elisp regex
|
|
||||||
(let ((newregex (rxt-pcre-to-elisp regexstr)))
|
|
||||||
(when bang
|
|
||||||
(setq newregex (s-replace "\\" "\\\\" newregex)))
|
|
||||||
(kill-new newregex)
|
|
||||||
(message "Copied regex to kill ring: %s" newregex)))
|
|
||||||
(t (re-builder)))))
|
|
||||||
|
|
||||||
(provide 'defuns-regex)
|
|
||||||
;;; defuns-regex.el ends here
|
|
|
@ -1,50 +0,0 @@
|
||||||
;;; defuns-sh.el
|
|
||||||
|
|
||||||
(defvar sh-extra-font-lock--keywords
|
|
||||||
`((doom/sh-extra-font-lock--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 doom/sh-extra-font-lock--is-in-double-quoted-string ()
|
|
||||||
"Non-nil if point in inside a double-quoted string."
|
|
||||||
(let ((state (syntax-ppss)))
|
|
||||||
(eq (nth 3 state) ?\")))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/sh-extra-font-lock--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 (doom/sh-extra-font-lock--is-in-double-quoted-string))))
|
|
||||||
res))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|sh-extra-font-lock-activate ()
|
|
||||||
"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 doom/inf-shell ()
|
|
||||||
(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)))))
|
|
||||||
|
|
||||||
(provide 'defuns-sh)
|
|
||||||
;;; defuns-sh.el ends here
|
|
|
@ -1,11 +0,0 @@
|
||||||
;;; defuns-text.el
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom:insert-date "defuns-text" nil t)
|
|
||||||
(evil-define-command doom:insert-date (beg end &optional format)
|
|
||||||
(interactive "<r><a>")
|
|
||||||
(when (and (evil-visual-state-p) beg end)
|
|
||||||
(kill-region beg end))
|
|
||||||
(insert (format-time-string (or format "%x"))))
|
|
||||||
|
|
||||||
(provide 'defuns-text)
|
|
||||||
;;; defuns-text.el ends here
|
|
|
@ -1,73 +0,0 @@
|
||||||
;;; defuns-typescript.el
|
|
||||||
|
|
||||||
(defvar ts-externs-vars-re
|
|
||||||
(concat "\\_<"
|
|
||||||
(regexp-opt
|
|
||||||
'("__dirname" "__filename"))
|
|
||||||
"\\_>"))
|
|
||||||
|
|
||||||
(defvar ts-externs-fns-re
|
|
||||||
(concat "\\_<"
|
|
||||||
(regexp-opt
|
|
||||||
'("Buffer" "clearInterval" "clearTimeout" "require" "setInterval"
|
|
||||||
"setTimeout" "querystring" "setImmediate" "clearImmediate"))
|
|
||||||
"\\_>"))
|
|
||||||
|
|
||||||
(defvar ts-ecma-externs-re
|
|
||||||
(concat "\\_<"
|
|
||||||
(regexp-opt '("decoreURI" "decoreURIComponent" "encodeURI"
|
|
||||||
"encodeURIComponent" "escape" "eval" "isFinite"
|
|
||||||
"isNaN" "parseFloat" "parseInt" "escape" "unescape"))
|
|
||||||
"\\_>"))
|
|
||||||
|
|
||||||
(defface ts-object-property '((t (:inherit font-lock-function-name-face)))
|
|
||||||
"")
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom|ts-fontify ()
|
|
||||||
(font-lock-add-keywords
|
|
||||||
nil `((,ts-externs-vars-re
|
|
||||||
. 'font-lock-builtin-face)
|
|
||||||
(,ts-externs-fns-re
|
|
||||||
. 'font-lock-keyword-face)
|
|
||||||
(,ts-ecma-externs-re
|
|
||||||
. 'font-lock-builtin-face)
|
|
||||||
;; Lambda character
|
|
||||||
(" \\(=>\\) "
|
|
||||||
. 'font-lock-preprocessor-face)
|
|
||||||
;; $-prefixed variables
|
|
||||||
("\\_<\\$[[:alnum:]_]+\\_>"
|
|
||||||
. 'font-lock-keyword-face)
|
|
||||||
;; object keys
|
|
||||||
("\\(?:^\\|,\\|{\\)\\s-*\\([[:alpha:]_$][[:alnum:]_$]*\\)\\s-*:"
|
|
||||||
1 'ts-object-property)
|
|
||||||
;; variable.prefixes
|
|
||||||
("\\_<\\([a-z_$][[:alnum:]_$]*\\)\\."
|
|
||||||
1 'font-lock-variable-name-face)
|
|
||||||
;; functioncalls()
|
|
||||||
("\\_<\\([a-z_$][[:alnum:]_$]*\\)("
|
|
||||||
1 'font-lock-function-name-face)
|
|
||||||
;; PascalCase ClassNames
|
|
||||||
("\\_<[A-Z][a-z0-9_]+\\_>"
|
|
||||||
. 'font-lock-type-face)
|
|
||||||
;; CONSTANTS
|
|
||||||
("\\_<[A-Z0-9_]+\\_>"
|
|
||||||
. 'font-lock-builtin-face)
|
|
||||||
;; Import froms
|
|
||||||
("^\\s-*import\\s-+\\(?:{[^}]*}\\|[^ ]+\\|[^ ]+\\s-+as\\s-+[^ ]+\\)\\s-+\\(from\\)\\s-"
|
|
||||||
(1 'font-lock-keyword-face))
|
|
||||||
("^\\s-*import\\s-+\\(?:[^ ]+\\s-+\\(as\\)\\s-+[^ ]+\\)\\s-+from\\s-"
|
|
||||||
(1 'font-lock-keyword-face))
|
|
||||||
|
|
||||||
;; ES6 Lambda parameters (...) => {}
|
|
||||||
(,(concat
|
|
||||||
"\\s-(\\s-*"
|
|
||||||
typescript--name-start-re)
|
|
||||||
,(list (concat "\\(" typescript--name-re "\\)\\(\\s-*).*\\)?\\s-*")
|
|
||||||
'(backward-char)
|
|
||||||
'(end-of-line)
|
|
||||||
'(1 font-lock-variable-name-face)))
|
|
||||||
)))
|
|
||||||
|
|
||||||
(provide 'defuns-typescript)
|
|
||||||
;;; defuns-typescript.el ends here
|
|
|
@ -1,45 +0,0 @@
|
||||||
;;; defuns-web.el
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/web-html-email2mailto (beg end)
|
|
||||||
(interactive "r")
|
|
||||||
(replace-regexp "\\b\\([a-zA-Z0-9._+-%]+@[a-zA-Z0-9-.]+\\.[a-zA-Z]+\\)\\b"
|
|
||||||
"<a href=\"mailto:\\1\">\\1</a>"
|
|
||||||
nil beg end))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/web-html-url2anchor (beg end)
|
|
||||||
(interactive "r")
|
|
||||||
(replace-regexp "\\bhttps?://.+?\\b"
|
|
||||||
"<a href=\"\\1\">\\1</a>"
|
|
||||||
nil beg end))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun doom/web-refresh-browser ()
|
|
||||||
(interactive)
|
|
||||||
(call-process-shell-command "osascript -e 'tell application \"Google Chrome\" to tell the active tab of its first window to reload' &" nil 0))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'doom/html-entities "defuns-web" nil t)
|
|
||||||
(evil-define-operator doom/html-entities (bang beg end)
|
|
||||||
"HTML encode/decode the selected region. Based on Xah's replace HTML named entities
|
|
||||||
function @ http://ergoemacs.org/emacs/elisp_replace_html_entities_command.html"
|
|
||||||
(interactive "<!><r>")
|
|
||||||
(let ((reps [[" " " "] [" " " "] [" " " "] [" " " "]
|
|
||||||
["‏" ""] ["‎" ""] ["‍" ""] ["‌" ""]
|
|
||||||
["¡" "¡"] ["¢" "¢"] ["£" "£"] ["¤" "¤"] ["¥" "¥"] ["¦" "¦"] ["§" "§"] ["¨" "¨"] ["©" "©"] ["ª" "ª"] ["«" "«"] ["¬" "¬"] ["­" ""] ["®" "®"] ["¯" "¯"] ["°" "°"] ["±" "±"] ["²" "²"] ["³" "³"] ["´" "´"] ["µ" "µ"] ["¶" "¶"] ["·" "·"] ["¸" "¸"] ["¹" "¹"] ["º" "º"] ["»" "»"] ["¼" "¼"] ["½" "½"] ["¾" "¾"] ["¿" "¿"]
|
|
||||||
["À" "À"] ["Á" "Á"] ["Â" "Â"] ["Ã" "Ã"] ["Ä" "Ä"] ["Å" "Å"] ["Æ" "Æ"] ["Ç" "Ç"] ["È" "È"] ["É" "É"] ["Ê" "Ê"] ["Ë" "Ë"] ["Ì" "Ì"] ["Í" "Í"] ["Î" "Î"] ["Ï" "Ï"] ["Ð" "Ð"] ["Ñ" "Ñ"] ["Ò" "Ò"] ["Ó" "Ó"] ["Ô" "Ô"] ["Õ" "Õ"] ["Ö" "Ö"] ["×" "×"] ["Ø" "Ø"] ["Ù" "Ù"] ["Ú" "Ú"] ["Û" "Û"] ["Ü" "Ü"] ["Ý" "Ý"] ["Þ" "Þ"] ["ß" "ß"] ["à" "à"] ["á" "á"] ["â" "â"] ["ã" "ã"] ["ä" "ä"] ["å" "å"] ["æ" "æ"] ["ç" "ç"] ["è" "è"] ["é" "é"] ["ê" "ê"] ["ë" "ë"] ["ì" "ì"] ["í" "í"] ["î" "î"] ["ï" "ï"] ["ð" "ð"] ["ñ" "ñ"] ["ò" "ò"] ["ó" "ó"] ["ô" "ô"] ["õ" "õ"] ["ö" "ö"]
|
|
||||||
["÷" "÷"] ["ø" "ø"] ["ù" "ù"] ["ú" "ú"] ["û" "û"] ["ü" "ü"] ["ý" "ý"] ["þ" "þ"] ["ÿ" "ÿ"] ["ƒ" "ƒ"]
|
|
||||||
["Α" "Α"] ["Β" "Β"] ["Γ" "Γ"] ["Δ" "Δ"] ["Ε" "Ε"] ["Ζ" "Ζ"] ["Η" "Η"] ["Θ" "Θ"] ["Ι" "Ι"] ["Κ" "Κ"] ["Λ" "Λ"] ["Μ" "Μ"] ["Ν" "Ν"] ["Ξ" "Ξ"] ["Ο" "Ο"] ["Π" "Π"] ["Ρ" "Ρ"] ["Σ" "Σ"] ["Τ" "Τ"] ["Υ" "Υ"] ["Φ" "Φ"] ["Χ" "Χ"] ["Ψ" "Ψ"] ["Ω" "Ω"] ["α" "α"] ["β" "β"] ["γ" "γ"] ["δ" "δ"] ["ε" "ε"] ["ζ" "ζ"] ["η" "η"] ["θ" "θ"] ["ι" "ι"] ["κ" "κ"] ["λ" "λ"] ["μ" "μ"] ["ν" "ν"] ["ξ" "ξ"] ["ο" "ο"] ["π" "π"] ["ρ" "ρ"] ["ς" "ς"] ["σ" "σ"] ["τ" "τ"] ["υ" "υ"] ["φ" "φ"] ["χ" "χ"] ["ψ" "ψ"] ["ω" "ω"] ["ϑ" "ϑ"] ["ϒ" "ϒ"] ["ϖ" "ϖ"]
|
|
||||||
["•" "•"] ["…" "…"] ["′" "′"] ["″" "″"] ["‾" "‾"] ["⁄" "⁄"] ["℘" "℘"] ["ℑ" "ℑ"] ["ℜ" "ℜ"] ["™" "™"] ["ℵ" "ℵ"] ["←" "←"] ["↑" "↑"] ["→" "→"] ["↓" "↓"] ["↔" "↔"] ["↵" "↵"] ["⇐" "⇐"] ["⇑" "⇑"] ["⇒" "⇒"] ["⇓" "⇓"] ["⇔" "⇔"] ["∀" "∀"] ["∂" "∂"] ["∃" "∃"] ["∅" "∅"] ["∇" "∇"] ["∈" "∈"] ["∉" "∉"] ["∋" "∋"] ["∏" "∏"] ["∑" "∑"] ["−" "−"] ["∗" "∗"] ["√" "√"] ["∝" "∝"] ["∞" "∞"] ["∠" "∠"] ["∧" "∧"] ["∨" "∨"] ["∩" "∩"] ["∪" "∪"] ["∫" "∫"] ["∴" "∴"] ["∼" "∼"] ["≅" "≅"] ["≈" "≈"] ["≠" "≠"] ["≡" "≡"] ["≤" "≤"] ["≥" "≥"] ["⊂" "⊂"] ["⊃" "⊃"] ["⊄" "⊄"] ["⊆" "⊆"] ["⊇" "⊇"] ["⊕" "⊕"] ["⊗" "⊗"] ["⊥" "⊥"] ["⋅" "⋅"] ["⌈" "⌈"] ["⌉" "⌉"] ["⌊" "⌊"] ["⌋" "⌋"] ["⟨" "〈"] ["⟩" "〉"] ["◊" "◊"] ["♠" "♠"] ["♣" "♣"] ["♥" "♥"] ["♦" "♦"] [""" "\""] ["Œ" "Œ"] ["œ" "œ"] ["Š" "Š"] ["š" "š"] ["Ÿ" "Ÿ"] ["ˆ" "ˆ"] ["˜" "˜"] ["–" "–"] ["—" "—"] ["‘" "‘"] ["’" "’"] ["‚" "‚"] ["“" "“"] ["”" "”"] ["„" "„"] ["†" "†"] ["‡" "‡"] ["‰" "‰"] ["‹" "‹"] ["›" "›"] ["€" "€"]
|
|
||||||
]))
|
|
||||||
(save-restriction
|
|
||||||
(narrow-to-region beg end)
|
|
||||||
(let (case-fold-search)
|
|
||||||
(mapc (lambda (rep)
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (search-forward (elt rep (if bang 0 1)) nil t)
|
|
||||||
(replace-match (elt rep (if bang 1 0)) 'FIXEDCASE 'LITERAL)))
|
|
||||||
reps)))))
|
|
||||||
|
|
||||||
(provide 'defuns-web)
|
|
||||||
;;; defuns-web.el ends here
|
|
|
@ -1,45 +0,0 @@
|
||||||
;;; macros-org.el
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defmacro define-org-section! (type directory &optional id-func link-glob)
|
|
||||||
(setq directory (f-slash directory))
|
|
||||||
(let* ((type-str (symbol-name type))
|
|
||||||
(link-sym (intern (format "doom/org-link-%s" type-str)))
|
|
||||||
(dir-var (intern (format "org-directory-%s" type-str))))
|
|
||||||
`(progn
|
|
||||||
;; Variable containing directory: `org-directory-%s'
|
|
||||||
(defvar ,dir-var ,(expand-file-name directory org-directory))
|
|
||||||
|
|
||||||
;; Open helm in directory: `doom/helm-org-%s'
|
|
||||||
(evil-define-command ,(intern (format "doom:org-search-%s" type-str)) ()
|
|
||||||
(interactive)
|
|
||||||
(let ((default-directory (concat ,dir-var "/" (format-time-string "%Y") "/")))
|
|
||||||
(helm-find-files nil)))
|
|
||||||
|
|
||||||
;; Open helm in directory: `doom/helm-org-%s'
|
|
||||||
(defun ,(intern (format "doom/helm-org-find-file-in-%s" type-str)) ()
|
|
||||||
(interactive)
|
|
||||||
(helm-do-ag (f-slash ,dir-var)))
|
|
||||||
|
|
||||||
;; Org link handler
|
|
||||||
(defun ,link-sym (id)
|
|
||||||
(let ((path (f-glob (format (or ,link-glob "%s.org") id) ,dir-var)))
|
|
||||||
(unless path
|
|
||||||
(error "ID not found: %s" id))
|
|
||||||
(org-open-file (car path) t)))
|
|
||||||
(org-add-link-type ,type-str ',link-sym)
|
|
||||||
|
|
||||||
;; Org completion handler
|
|
||||||
(defun ,(intern (format "org-%s-complete-link" type-str)) ()
|
|
||||||
(let* ((default-directory (f-slash ,dir-var))
|
|
||||||
(file (org-iread-file-name "> "))
|
|
||||||
(relpath (f-relative file ,dir-var)))
|
|
||||||
(when (and (not (file-exists-p file))
|
|
||||||
(y-or-n-p (format "Create %s?" relpath)))
|
|
||||||
(write-region "" nil file)
|
|
||||||
(message "Created %s" file))
|
|
||||||
(format "%s:%s" ,type-str ,(if id-func `(funcall ,id-func relpath) '(f-no-ext relpath)))
|
|
||||||
)))))
|
|
||||||
|
|
||||||
(provide 'macros-org)
|
|
||||||
;;; macros-org.el ends here
|
|
Loading…
Add table
Add a link
Reference in a new issue