Move {core,modules}/lib/*.el to {core,modules}/defuns/
This commit is contained in:
parent
976d60b5da
commit
5eb60220ee
41 changed files with 68 additions and 36 deletions
|
@ -1,81 +0,0 @@
|
|||
;;; defuns-cc.el --- for module-cc.el
|
||||
|
||||
(defun narf--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 narf|init-c/c++-settings ()
|
||||
(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 'narf--c-lineup-inclass)
|
||||
;; DEL mapping interferes with smartparens and my custom DEL binding
|
||||
(define-key c-mode-map (kbd "DEL") nil))
|
||||
|
||||
(defun narf--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 narf|init-c++-C11-highlights ()
|
||||
;; C++11 syntax support (until cc-mode is updated)
|
||||
(require 'font-lock)
|
||||
;; labels, case, public, private, protected, namespace-tags
|
||||
(narf--copy-face 'font-lock-label-face 'font-lock-keyword-face)
|
||||
;; comment markups such as Javadoc-tags
|
||||
(narf--copy-face 'font-lock-doc-markup-face 'font-lock-doc-face)
|
||||
;; comment markups
|
||||
(narf--copy-face 'font-lock-doc-string-face 'font-lock-comment-face)
|
||||
(setq font-lock-maximum-decoration t)
|
||||
|
||||
;; We could place some regexes into `c-mode-common-hook', but
|
||||
;; note that their evaluation order matters.
|
||||
(font-lock-add-keywords
|
||||
nil '(;; complete some fundamental keywords
|
||||
("\\<\\(void\\|unsigned\\|signed\\|char\\|short\\|bool\\|int\\|long\\|float\\|double\\)\\>" . font-lock-keyword-face)
|
||||
;; namespace names and tags - these are rendered as constants by cc-mode
|
||||
("\\<\\(\\w+::\\)" . font-lock-function-name-face)
|
||||
;; new C++11 keywords
|
||||
("\\<\\(alignof\\|alignas\\|constexpr\\|decltype\\|noexcept\\|nullptr\\|static_assert\\|thread_local\\|override\\|final\\)\\>" . font-lock-keyword-face)
|
||||
("\\<\\(char16_t\\|char32_t\\)\\>" . font-lock-keyword-face)
|
||||
;; PREPROCESSOR_CONSTANT, PREPROCESSORCONSTANT
|
||||
("\\<[A-Z]*_[A-Z_]+\\>" . font-lock-constant-face)
|
||||
("\\<[A-Z]\\{3,\\}\\>" . font-lock-constant-face)
|
||||
;; hexadecimal numbers
|
||||
("\\<0[xX][0-9A-Fa-f]+\\>" . font-lock-constant-face)
|
||||
;; integer/float/scientific numbers
|
||||
("\\<[\\-+]*[0-9]*\\.?[0-9]+\\([ulUL]+\\|[eE][\\-+]?[0-9]+\\)?\\>" . font-lock-constant-face)
|
||||
;; 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
|
||||
|
||||
;; user-defined types (rather project-specific)
|
||||
("\\<[A-Za-z_]+[A-Za-z_0-9]*_\\(type\\|ptr\\)\\>" . font-lock-type-face)
|
||||
("\\<\\(xstring\\|xchar\\)\\>" . font-lock-type-face)
|
||||
) t))
|
||||
|
||||
|
||||
(provide 'defuns-cc)
|
||||
;;; defuns-cc.el ends here
|
|
@ -1,61 +0,0 @@
|
|||
;;; defuns-eshell.el ---
|
||||
|
||||
(defun narf--eshell-in-prompt-p (&optional offset)
|
||||
(>= (- (point) (or offset 0)) (save-excursion (eshell-bol) (point))))
|
||||
|
||||
(defun narf--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 narf/eshell-prompt ()
|
||||
(concat (propertize (abbreviate-file-name (eshell/pwd)) 'face 'eshell-prompt)
|
||||
(propertize (narf--eshell-current-git-branch) 'face 'font-lock-function-name-face)
|
||||
(propertize " $ " 'face 'font-lock-constant-face)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/eshell-evil-append ()
|
||||
(interactive)
|
||||
(goto-char (point-max))
|
||||
(call-interactively 'evil-append))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/eshell-evil-append-maybe ()
|
||||
(interactive)
|
||||
(if (narf--eshell-in-prompt-p)
|
||||
(call-interactively 'evil-insert)
|
||||
(narf/eshell-append)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/eshell-evil-prepend ()
|
||||
(interactive)
|
||||
(eshell-bol)
|
||||
(call-interactively 'evil-insert))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/eshell-evil-prepend-maybe ()
|
||||
(interactive)
|
||||
(if (narf--eshell-in-prompt-p)
|
||||
(call-interactively 'evil-insert)
|
||||
(narf/eshell-prepend)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/eshell-evil-replace-maybe ()
|
||||
(interactive)
|
||||
(if (narf--eshell-in-prompt-p)
|
||||
(call-interactively 'evil-replace)
|
||||
(user-error "Cannot edit read-only region")))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/eshell-evil-replace-state-maybe ()
|
||||
(interactive)
|
||||
(if (narf--eshell-in-prompt-p)
|
||||
(call-interactively 'evil-replace-state)
|
||||
(user-error "Cannot edit read-only region")))
|
||||
|
||||
(provide 'defuns-eshell)
|
||||
;;; defuns-eshell.el ends here
|
|
@ -1,18 +0,0 @@
|
|||
;;; defuns-go.el
|
||||
|
||||
;; TODO Implement narf:go-get-package
|
||||
(defun narf--go-get-package ())
|
||||
|
||||
;;;###autoload
|
||||
(defun narf:go-test-run-all ()
|
||||
(interactive)
|
||||
(async-shell-command (format "cd '%s' && go test" (narf/project-root))))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf:go-test-run-package ()
|
||||
(interactive)
|
||||
(error "Not yet implemented")
|
||||
(async-shell-command (format "cd '%s' && go test %s" (narf/project-root) (narf--go-get-package))))
|
||||
|
||||
(provide 'defuns-go)
|
||||
;;; defuns-go.el ends here
|
|
@ -1,35 +0,0 @@
|
|||
;;; defuns-java.el ---
|
||||
|
||||
;; yasnippet defuns
|
||||
;;;###autoload
|
||||
(defun narf/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 narf/java-android-mode-in-tags (&rest tags)
|
||||
(-contains? tags (android-mode-tag-name)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/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 narf|android-mode-enable-maybe ()
|
||||
(let ((root (narf/project-root)))
|
||||
(when (or (narf/project-has-files "local.properties" root)
|
||||
(narf/project-has-files "AndroidManifest.xml" root)
|
||||
(narf/project-has-files "src/main/AndroidManifest.xml" root))
|
||||
(android-mode +1)
|
||||
(narf/set-build-command "./gradlew %s" "build.gradle"))))
|
||||
|
||||
(provide 'defuns-java)
|
||||
;;; defuns-java.el ends here
|
|
@ -1,16 +0,0 @@
|
|||
;;; defuns-lisp.el
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/elisp-find-function-at-pt ()
|
||||
(interactive)
|
||||
(let ((func (function-called-at-point)))
|
||||
(if func (find-function func))))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/elisp-find-function-at-pt-other-window ()
|
||||
(interactive)
|
||||
(let ((func (function-called-at-point)))
|
||||
(if func (find-function-other-window func))))
|
||||
|
||||
(provide 'defuns-lisp)
|
||||
;;; defuns-lisp.el ends here
|
|
@ -1,25 +0,0 @@
|
|||
;;; defuns-markdown.el --- for module-markdown.el
|
||||
|
||||
;; Implement strike-through formatting
|
||||
(defvar narf--markdown-regex-del
|
||||
"\\(^\\|[^\\]\\)\\(\\(~\\{2\\}\\)\\([^ \n \\]\\|[^ \n ]\\(?:.\\|\n[^\n]\\)*?[^\\ ]\\)\\(\\3\\)\\)")
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/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)
|
||||
narf--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 narf--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,86 +0,0 @@
|
|||
;;; defuns-org-attach.el --- custom attachment system
|
||||
|
||||
;; I know Org has its own attachment system, but I don't like it.
|
||||
|
||||
;;;###autoload (autoload 'narf:org-attach "defuns-org-attach" nil t)
|
||||
(evil-define-command narf:org-attach (&optional bang link)
|
||||
(interactive "<!><a>")
|
||||
(if (not link)
|
||||
(narf:org-attachment-list bang)
|
||||
(require 'org-download)
|
||||
(let ((new-path (if bang
|
||||
(format "%s/%s" (expand-file-name org-download-image-dir org-directory)
|
||||
(format "%s%s.%s"
|
||||
(f-base link)
|
||||
(format-time-string org-download-timestamp)
|
||||
(file-name-extension link))) buffer-file-name
|
||||
(org-download--fullname link))))
|
||||
(unless new-path
|
||||
(user-error "No file was provided"))
|
||||
(cond ((string-match-p "^https?://" link)
|
||||
(url-copy-file link new-path))
|
||||
(t (copy-file link new-path)))
|
||||
(let ((relpath (f-relative new-path default-directory)))
|
||||
(if (evil-visual-state-p)
|
||||
(org-insert-link nil (format "./%s" relpath) (buffer-substring-no-properties (region-beginning) (region-end)))
|
||||
(insert (format "[[./%s]]" relpath)))))))
|
||||
|
||||
;;;###autoload (autoload 'narf:org-attachment-list "defuns-org-attach" nil t)
|
||||
(evil-define-command narf:org-attachment-list (&optional bang)
|
||||
(interactive "<!>")
|
||||
(if bang
|
||||
(narf:org-attachment-cleanup)
|
||||
(let ((attachments (narf-org--get-attachments)))
|
||||
(unless attachments
|
||||
(user-error "No attachments in this file"))
|
||||
(helm :sources
|
||||
(helm-build-sync-source "Attachments"
|
||||
:candidates attachments
|
||||
:real-to-display 'narf-org--attachment-real-to-display
|
||||
:action '(("Go to Attachment in Buffer" . narf-org--attachment-find)
|
||||
("Reveal Attachment in Finder" . narf-org--attachment-reveal)
|
||||
("Open Attachment" . narf-org--attachment-open)
|
||||
("Delete Attachment" . narf-org--attachment-delete)))))))
|
||||
|
||||
;; TODO Improve
|
||||
;;;###autoload
|
||||
(defun narf/org-attachment-reveal ()
|
||||
(interactive)
|
||||
(let ((context (org-element-context)))
|
||||
(narf-open-with
|
||||
nil
|
||||
(if (and context (eq (org-element-type context) 'link))
|
||||
(f-dirname (org-element-property :path context))
|
||||
org-download-image-dir))))
|
||||
|
||||
(defun narf-org--get-attachments ()
|
||||
(org-element-map (org-element-parse-buffer) 'link
|
||||
(lambda (link)
|
||||
(when (and (string= (org-element-property :type link) "file")
|
||||
(string-prefix-p (format "./%s" org-download-image-dir)
|
||||
(org-element-property :path link)))
|
||||
(org-element-property :path link)))))
|
||||
|
||||
(defun narf-org--attachment-real-to-display (real)
|
||||
(propertize (f-filename real) 'face (if (file-exists-p real) 'helm-ff-file 'shadow)))
|
||||
|
||||
(defun narf-org--attachment-find (file)
|
||||
(search-forward-regexp (format "[[\\(file:\\)?%s]]" file) nil t)
|
||||
(ignore-errors
|
||||
(save-excursion
|
||||
(outline-previous-visible-heading 1)
|
||||
(org-show-subtree))))
|
||||
|
||||
(defun narf-org--attachment-reveal (file)
|
||||
(narf-open-with nil (f-dirname file)))
|
||||
|
||||
(defun narf-org--attachment-open (file)
|
||||
(narf-open-with nil file))
|
||||
|
||||
(defun narf-org--attachment-delete (file)
|
||||
(delete-file file)
|
||||
(narf-org--attachment-find file)
|
||||
(message "File deleted, now delete the link! (%s)" file))
|
||||
|
||||
(provide 'defuns-org-attach)
|
||||
;;; defuns-org-attach.el ends here
|
|
@ -1,134 +0,0 @@
|
|||
;;; defuns-org-crm.el --- for my custom org-based CRM
|
||||
|
||||
(defun narf--helm-org (&optional directory)
|
||||
(let ((helm-deft-dir-list `(,(or directory default-directory))))
|
||||
(helm-deft)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/helm-org ()
|
||||
(interactive)
|
||||
(narf--helm-org org-directory))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/helm-org-crm-projects ()
|
||||
(interactive)
|
||||
(narf--helm-org org-directory-projects))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/helm-org-crm-contacts ()
|
||||
(interactive)
|
||||
(narf--helm-org org-directory-contacts))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/helm-org-crm-invoices ()
|
||||
(interactive)
|
||||
(narf--helm-org org-directory-invoices))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/helm-org-writing ()
|
||||
(interactive)
|
||||
(let ((narf--helm-org-params '()))
|
||||
(narf--helm-org (expand-file-name "writing/" org-directory))))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-crm-link-contact (id)
|
||||
(org-open-file (narf--org-crm-id-to-path id 'contact) t))
|
||||
;;;###autoload
|
||||
(defun narf/org-crm-link-project (id)
|
||||
(org-open-file (narf--org-crm-id-to-path id 'project) t))
|
||||
;;;###autoload
|
||||
(defun narf/org-crm-link-invoice (id)
|
||||
(org-open-file (narf--org-crm-id-to-path id 'invoice) t))
|
||||
|
||||
(defun narf--org-complete (type)
|
||||
(let ((default-directory (symbol-value (intern (format "org-directory-%ss" type)))))
|
||||
(let* ((file (org-iread-file-name ">>> "))
|
||||
(match (s-match "^\\([0-9]+\\)[-.]" (f-filename file))))
|
||||
(unless (file-exists-p file)
|
||||
(message "Created %s" file)
|
||||
(write-region "" nil file))
|
||||
(unless match
|
||||
(user-error "Invalid file ID"))
|
||||
(format "%s:%s" type (cadr match)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun org-contact-complete-link () (narf--org-complete 'contact))
|
||||
;;;###autoload
|
||||
(defun org-project-complete-link () (narf--org-complete 'project))
|
||||
;;;###autoload
|
||||
(defun org-invoice-complete-link () (narf--org-complete 'invoice))
|
||||
|
||||
(defun narf--org-crm-assert-type (type)
|
||||
(unless (memq type '(project contact invoice))
|
||||
(user-error "Not a valid type: %s" type)))
|
||||
|
||||
(defun narf--org-crm-new-path (name type)
|
||||
(narf--org-crm-assert-type type)
|
||||
(let* ((prefix
|
||||
(replace-regexp-in-string
|
||||
"/+$" "" (symbol-value (intern (format "org-directory-%ss" type)))))
|
||||
(last-file (car-safe (sort (f-glob "*.org" prefix) 'string>))))
|
||||
(when last-file
|
||||
(let* ((old-id (narf--org-crm-path-to-id last-file type))
|
||||
(new-id (format "%04X" (1+ old-id))))
|
||||
(if (eq type 'invoice)
|
||||
(format "%s/%s-%s.org" prefix (format-time-string "%y%m") new-id)
|
||||
(format "%s/%s-%s.org" prefix
|
||||
new-id (replace-regexp-in-string "[][ !@#$%^&*()]" "-" name)))))))
|
||||
|
||||
(defun narf--org-crm-path-to-id (path type)
|
||||
(narf--org-crm-assert-type type)
|
||||
(let ((base (f-filename path)))
|
||||
(string-to-number
|
||||
(if (eq type 'invoice)
|
||||
(substring base (1+ (string-match-p "-" base)) (string-match-p ".org" base))
|
||||
(substring base 0 (string-match-p "[-.]" base)))
|
||||
16)))
|
||||
|
||||
(defun narf--org-crm-id-to-path (id type)
|
||||
(narf--org-crm-assert-type type)
|
||||
(let* ((prefix
|
||||
(replace-regexp-in-string
|
||||
"/+$" "" (symbol-value (intern (format "org-directory-%ss" type))))))
|
||||
(car-safe
|
||||
(f-glob (format (if (eq type 'invoice) "*-%04X.org" "%04X*.org")
|
||||
(string-to-number id 16))
|
||||
prefix))))
|
||||
|
||||
(defun narf--org-crm (&optional id type new-p)
|
||||
(let ((file (if new-p
|
||||
(or (narf--org-crm-new-path id type)
|
||||
(user-error "path could not be resolved: type(%s) name(%s)" type name))
|
||||
(or (narf--org-crm-id-to-path id type)
|
||||
(user-error "id %s could not be resolved in %s" id type))))
|
||||
(old-buffer (current-buffer)))
|
||||
(find-file file)
|
||||
(with-current-buffer old-buffer
|
||||
(when (evil-visual-state-p)
|
||||
(org-insert-link
|
||||
nil (format "%s:%s" (symbol-name type) (narf--org-crm-path-to-id file type))
|
||||
(buffer-substring-no-properties (region-beginning) (region-end)))))))
|
||||
|
||||
|
||||
;;;###autoload (autoload 'narf:org-crm-project "defuns-org-crm" nil t)
|
||||
(evil-define-command narf:org-crm-project (&optional bang name)
|
||||
(interactive "<!><a>")
|
||||
(if bang
|
||||
(narf--org-crm name 'project t)
|
||||
(narf/helm-org-crm-projects)))
|
||||
;;;###autoload (autoload 'narf:org-crm-contact "defuns-org-crm" nil t)
|
||||
(evil-define-command narf:org-crm-contact (&optional bang name)
|
||||
(interactive "<!><a>")
|
||||
(if bang
|
||||
(narf--org-crm name 'contact t)
|
||||
(narf/helm-org-crm-contacts)))
|
||||
;;;###autoload (autoload 'narf:org-crm-invoice "defuns-org-crm" nil t)
|
||||
(evil-define-command narf:org-crm-invoice (&optional bang)
|
||||
(interactive "<!>")
|
||||
(if bang
|
||||
(narf--org-crm nil 'invoice t)
|
||||
(narf/helm-org-crm-invoices)))
|
||||
|
||||
|
||||
(provide 'defuns-org-crm)
|
||||
;;; defuns-org-crm.el ends here
|
|
@ -1,306 +0,0 @@
|
|||
;;; defuns-org.el
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-open-notes ()
|
||||
(interactive)
|
||||
(find-file org-default-notes-file))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-open-todo ()
|
||||
(interactive)
|
||||
(find-file org-default-todo-file))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-insert-item (direction)
|
||||
"Inserts a new heading or item, depending on the context."
|
||||
(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)
|
||||
(cl-case direction
|
||||
('below
|
||||
(org-end-of-line)
|
||||
(org-insert-heading))
|
||||
('above
|
||||
(evil-first-non-blank)
|
||||
(org-insert-heading)))
|
||||
(when (org-element-property :checkbox context)
|
||||
(insert "[ ] ")))
|
||||
((memq type '(table table-row))
|
||||
(cl-case direction
|
||||
('below
|
||||
(org-table-insert-row))
|
||||
('above
|
||||
(narf/org-table-prepend-row-or-shift-up))))
|
||||
(t
|
||||
(cl-case direction
|
||||
('below
|
||||
(org-insert-heading-after-current))
|
||||
('above
|
||||
(org-back-to-heading)
|
||||
(org-insert-heading)))
|
||||
(when (org-element-property :todo-type context)
|
||||
(org-todo 'todo))))
|
||||
(evil-append-line 1)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/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 narf/org-dwim-at-point ()
|
||||
(interactive)
|
||||
(let* ((scroll-pt (window-start))
|
||||
(context (org-element-lineage
|
||||
(org-element-context)
|
||||
'(table table-row clock comment comment-block footnote-definition
|
||||
footnote-reference headline inlinetask keyword link latex-fragment
|
||||
latex-environment src-block inline-src-block item plain-list
|
||||
timestamp babel-call)
|
||||
t))
|
||||
(type (org-element-type context))
|
||||
(value (org-element-property :value context)))
|
||||
(cond
|
||||
((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)))
|
||||
|
||||
((memq type '(headline))
|
||||
(org-remove-latex-fragment-image-overlays
|
||||
(save-excursion (org-beginning-of-line) (point))
|
||||
(save-excursion (org-end-of-subtree) (point)))
|
||||
(org-map-entries 'org-toggle-latex-fragment t 'tree)
|
||||
(narf/org-refresh-inline-images))
|
||||
|
||||
((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-toggle-latex-fragment))
|
||||
|
||||
((memq type '(link))
|
||||
(org-open-at-point))
|
||||
|
||||
(t (narf/org-refresh-inline-images)))
|
||||
(set-window-start nil scroll-pt)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-refresh-inline-images ()
|
||||
(interactive)
|
||||
(if (> (length org-inline-image-overlays) 0)
|
||||
(org-remove-inline-images)
|
||||
(org-display-inline-images
|
||||
nil t
|
||||
(save-excursion (org-back-to-heading) (point))
|
||||
(save-excursion (org-end-of-subtree) (point)))))
|
||||
|
||||
;; Formatting shortcuts
|
||||
;;;###autoload
|
||||
(defun narf/org-surround (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))))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-word-count (beg end &optional count-footnotes?)
|
||||
"Report the number of words in the Org mode buffer or selected region.
|
||||
Ignores:
|
||||
- comments
|
||||
- tables
|
||||
- source code blocks (#+BEGIN_SRC ... #+END_SRC, and inline blocks)
|
||||
- hyperlinks (but does count words in hyperlink descriptions)
|
||||
- tags, priorities, and TODO keywords in headers
|
||||
- sections tagged as 'not for export'.
|
||||
|
||||
The text of footnote definitions is ignored, unless the optional argument
|
||||
COUNT-FOOTNOTES? is non-nil."
|
||||
(interactive "r")
|
||||
(unless mark-active
|
||||
(setf beg (point-min)
|
||||
end (point-max)))
|
||||
(let ((wc 0))
|
||||
(save-excursion
|
||||
(goto-char beg)
|
||||
(while (< (point) end)
|
||||
(cond
|
||||
;; Ignore comments.
|
||||
((or (org-at-comment-p) (org-at-table-p))
|
||||
nil)
|
||||
;; Ignore hyperlinks. But if link has a description, count
|
||||
;; the words within the description.
|
||||
((looking-at org-bracket-link-analytic-regexp)
|
||||
(when (match-string-no-properties 5)
|
||||
(let ((desc (match-string-no-properties 5)))
|
||||
(save-match-data
|
||||
(incf wc (length (remove "" (org-split-string
|
||||
desc "\\W")))))))
|
||||
(goto-char (match-end 0)))
|
||||
((looking-at org-any-link-re)
|
||||
(goto-char (match-end 0)))
|
||||
;; Ignore source code blocks.
|
||||
((org-between-regexps-p "^#\\+BEGIN_SRC\\W" "^#\\+END_SRC\\W")
|
||||
nil)
|
||||
;; Ignore inline source blocks, counting them as 1 word.
|
||||
((save-excursion
|
||||
(backward-char)
|
||||
(looking-at org-babel-inline-src-block-regexp))
|
||||
(goto-char (match-end 0))
|
||||
(setf wc (+ 2 wc)))
|
||||
;; Ignore footnotes.
|
||||
((and (not count-footnotes?)
|
||||
(or (org-footnote-at-definition-p)
|
||||
(org-footnote-at-reference-p)))
|
||||
nil)
|
||||
(t
|
||||
(let ((contexts (org-context)))
|
||||
(cond
|
||||
;; Ignore tags and TODO keywords, etc.
|
||||
((or (assoc :todo-keyword contexts)
|
||||
(assoc :priority contexts)
|
||||
(assoc :keyword contexts)
|
||||
(assoc :checkbox contexts))
|
||||
nil)
|
||||
;; Ignore sections marked with tags that are
|
||||
;; excluded from export.
|
||||
((assoc :tags contexts)
|
||||
(if (intersection (org-get-tags-at) org-export-exclude-tags
|
||||
:test 'equal)
|
||||
(org-forward-same-level 1)
|
||||
nil))
|
||||
(t
|
||||
(incf wc))))))
|
||||
(re-search-forward "\\w+\\W*")))
|
||||
(message (format "%d words in %s." wc
|
||||
(if mark-active "region" "buffer")))))
|
||||
|
||||
;;;###autoload (autoload 'narf:org-export "defuns-org" nil t)
|
||||
(evil-define-command narf:org-export (dest)
|
||||
(interactive "<a>")
|
||||
(let ((path (if (string-match-p "^[/~]" dest)
|
||||
dest
|
||||
(expand-file-name dest default-directory))))
|
||||
(if (shell-command
|
||||
(format "/usr/local/bin/pandoc '%s' -o '%s'"
|
||||
(buffer-file-name) path))
|
||||
(message "Done! Exported to: %s" path)
|
||||
(user-error "Export failed"))))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/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))))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-next-row ()
|
||||
(interactive)
|
||||
(if (org-at-table-p) (org-table-next-row) (org-down-element)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-previous-row ()
|
||||
(interactive)
|
||||
(if (org-at-table-p) (narf--org-table-previous-row) (org-up-element)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-next-field ()
|
||||
(interactive)
|
||||
(if (org-at-table-p) (org-table-next-field) (org-end-of-line)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-previous-field ()
|
||||
(interactive)
|
||||
(if (org-at-table-p) (org-table-previous-field) (org-beginning-of-line)))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-append-field-or-shift-right ()
|
||||
(interactive)
|
||||
(org-shiftmetaright)
|
||||
(when (org-at-table-p) (org-metaright)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-prepend-field-or-shift-left ()
|
||||
(interactive)
|
||||
(if (org-at-table-p)
|
||||
(org-shiftmetaright)
|
||||
(org-shiftmetaleft)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-append-row-or-shift-down ()
|
||||
(interactive)
|
||||
(org-shiftmetadown)
|
||||
(when (org-at-table-p) (org-metadown)))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/org-table-prepend-row-or-shift-up ()
|
||||
(interactive)
|
||||
(if (org-at-table-p)
|
||||
(org-shiftmetadown)
|
||||
(org-shiftmetaup)))
|
||||
|
||||
(defun narf--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)
|
||||
(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))))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/-org-capture-changelog ()
|
||||
;; TODO
|
||||
)
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/-org-capture-choose ()
|
||||
;; TODO
|
||||
)
|
||||
|
||||
(provide 'defuns-org)
|
||||
;;; defuns-org.el ends here
|
|
@ -1,11 +0,0 @@
|
|||
;;; defuns-python.el
|
||||
|
||||
;;;###autoload
|
||||
(defun narf*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)))
|
||||
|
||||
(provide 'defuns-python)
|
||||
;;; defuns-python.el ends here
|
|
@ -1,40 +0,0 @@
|
|||
;;; defuns-regex.el
|
||||
|
||||
;;;###autoload
|
||||
(defun narf|reb-cleanup ()
|
||||
(replace-regexp "^[ \n]*" "" nil (point-min) (point-max))
|
||||
(text-scale-set 2)
|
||||
(goto-char 2))
|
||||
|
||||
;;;###autoload (autoload 'narf:regex "defuns-regex" nil t)
|
||||
(evil-define-operator narf: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,14 +0,0 @@
|
|||
;;; defuns-ruby.el
|
||||
|
||||
;;;###autoload
|
||||
(defun narf|ruby-load-file (&optional file)
|
||||
(let ((file (or file buffer-file-name)))
|
||||
(when (and (eq major-mode 'ruby-mode)
|
||||
(featurep 'robe)
|
||||
(not (string= (f-base file) "Gemfile"))
|
||||
(file-exists-p buffer-file-name))
|
||||
(unless robe-running (robe-start 1))
|
||||
(when robe-running (ruby-load-file file)))))
|
||||
|
||||
(provide 'defuns-ruby)
|
||||
;;; defuns-ruby.el ends here
|
|
@ -1,31 +0,0 @@
|
|||
;;; defuns-scss.el
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/scss-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))
|
||||
(setq 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)))))
|
||||
|
||||
(provide 'defuns-scss)
|
||||
;;; defuns-scss.el ends here
|
|
@ -1,45 +0,0 @@
|
|||
;;; defuns-sh.el
|
||||
|
||||
(defvar sh-extra-font-lock--keywords
|
||||
'((narf/sh-extra-font-lock--match-var-in-double-quoted-string
|
||||
(2 font-lock-variable-name-face prepend))))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/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 narf/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 (narf/sh-extra-font-lock--is-in-double-quoted-string))))
|
||||
res))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf|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 narf/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,23 +0,0 @@
|
|||
;;; defuns-web.el
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/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 narf/web-html-url2anchor (beg end)
|
||||
(interactive "r")
|
||||
(replace-regexp "\\bhttps?://.+?\\b"
|
||||
"<a href=\"\\1\">\\1</a>"
|
||||
nil beg end))
|
||||
|
||||
;;;###autoload
|
||||
(defun narf/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))
|
||||
|
||||
(provide 'defuns-web)
|
||||
;;; defuns-web.el ends here
|
Loading…
Add table
Add a link
Reference in a new issue