summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2021-03-04 18:36:46 -0600
committerCase Duckworth2021-03-04 18:36:46 -0600
commit453c4b112f8d702b81b8c329dd2b452b4de5bd94 (patch)
treec71818e1cacb2371458aa8484f5127fea5151a8c
parentConfigure ibuffer (diff)
parentFix hook (diff)
downloademacs-453c4b112f8d702b81b8c329dd2b452b4de5bd94.tar.gz
emacs-453c4b112f8d702b81b8c329dd2b452b4de5bd94.zip
Merge branch 'no-org' of tildegit.org:acdw/emacs into no-org
-rw-r--r--init.el249
1 files changed, 246 insertions, 3 deletions
diff --git a/init.el b/init.el index fdee1bb..94e2a0e 100644 --- a/init.el +++ b/init.el
@@ -18,6 +18,10 @@
18;; 18;;
19;;; Comentary: 19;;; Comentary:
20;; 20;;
21;;; Research:
22;; (map! :leader (:prefix "w" :desc "Toggle full screen buffer" "f"
23;; #'toggle-maximize-buffer))
24;;
21;;; Code: 25;;; Code:
22 26
23;; User information 27;; User information
@@ -345,6 +349,7 @@
345;; Theming 349;; Theming
346 350
347(use-package form-feed 351(use-package form-feed
352 :demand
348 :config (global-form-feed-mode +1)) 353 :config (global-form-feed-mode +1))
349 354
350(use-package modus-themes 355(use-package modus-themes
@@ -441,7 +446,9 @@
441 (write-region "" nil ispell-personal-dictionary nil 0))) 446 (write-region "" nil ispell-personal-dictionary nil 0)))
442 447
443(use-package flyspell-correct 448(use-package flyspell-correct
444 :bind ("C-;" . flyspell-correct-wrapper)) 449 :after flyspell
450 :bind (:map flyspell-mode-map
451 ("C-;" . flyspell-correct-wrapper)))
445 452
446(setq-default show-paren-delay 0 453(setq-default show-paren-delay 0
447 show-paren-style 'mixed 454 show-paren-style 'mixed
@@ -464,13 +471,18 @@
464(use-package reformatter 471(use-package reformatter
465 :demand) 472 :demand)
466 473
474(setq-default smie-indent-basic 8)
475
467;; Shell scripts 476;; Shell scripts
468(setq-default sh-basic-offset 8 477(setq-default sh-basic-offset 8
469 smie-indent-basic 8) 478 ;; try to indent like shfmt
479 sh-indent-after-case 0
480 sh-indent-for-case-alt '+
481 sh-indent-for-case-label 0)
470 482
471(use-package flymake-shellcheck 483(use-package flymake-shellcheck
472 :when (executable-find "shellcheck") 484 :when (executable-find "shellcheck")
473 :hook sh-mode) 485 :hook (sh-mode . flymake-shellcheck-load))
474 486
475(when (executable-find "shfmt") 487(when (executable-find "shfmt")
476 (reformatter-define sh-format 488 (reformatter-define sh-format
@@ -794,3 +806,234 @@
794 (add-to-list 'exec-path "C:/Program Files/Mozilla Firefox")) 806 (add-to-list 'exec-path "C:/Program Files/Mozilla Firefox"))
795 807
796(bind-key [remap just-one-space] #'cycle-spacing) 808(bind-key [remap just-one-space] #'cycle-spacing)
809
810;; Org mode
811;; org-return-dwim (unpacakged)
812(defun unpackaged/org-element-descendant-of (type element)
813 "Return non-nil if ELEMENT is a descendant of TYPE.
814 TYPE should be an element type, like `item' or `paragraph'.
815 ELEMENT should be a list like that returned by `org-element-context'."
816 ;; MAYBE: Use `org-element-lineage'.
817 (when-let* ((parent (org-element-property :parent element)))
818 (or (eq type (car parent))
819 (unpackaged/org-element-descendant-of type parent))))
820
821(defun unpackaged/org-return-dwim (&optional default)
822 "A helpful replacement for `org-return'. With prefix, call `org-return'.
823
824 On headings, move point to position after entry content. In
825 lists, insert a new item or end the list, with checkbox if
826 appropriate. In tables, insert a new row or end the table."
827 ;; Inspired by John Kitchin:
828 ;; http://kitchingroup.cheme.cmu.edu/blog/2017/04/09/A-better-return-in-org-mode/
829 (interactive "P")
830 (if default
831 (org-return)
832 (cond
833 ;; Act depending on context around point.
834
835 ;; NOTE: I prefer RET to not follow links, but by uncommenting
836 ;; this block, links will be followed.
837 ;; FURTHER NOTE: Ideally, I would follow links unless point
838 ;; /appeared/ to be at the end of the line (even if it's still
839 ;; inside the link) -- when it would do `org-return'. That
840 ;; would take some /doing/, however.
841
842 ;; ((eq 'link (car (org-element-context)))
843 ;; ;; Link: Open it.
844 ;; (org-open-at-point-global))
845
846 ((org-at-heading-p)
847 ;; Heading: Move to position after entry content.
848 ;; NOTE: This is probably the most interesting feature of this function.
849 (let ((heading-start (org-entry-beginning-position)))
850 (goto-char (org-entry-end-position))
851 (cond ((and (org-at-heading-p)
852 (= heading-start (org-entry-beginning-position)))
853 ;; Entry ends on its heading; add newline after
854 (end-of-line)
855 (insert "\n\n"))
856 (t
857 ;; Entry ends after its heading; back up
858 (forward-line -1)
859 (end-of-line)
860 (when (org-at-heading-p)
861 ;; At the same heading
862 (forward-line)
863 (insert "\n")
864 (forward-line -1))
865 ;; FIXME: looking-back is supposed to be called with
866 ;; more arguments.
867 (while (not (looking-back (rx
868 (repeat 3
869 (seq (optional blank)
870 "\n")))
871 nil))
872 (insert "\n"))
873 (forward-line -1)))))
874
875 ((org-at-item-checkbox-p)
876 ;; Checkbox: Insert new item with checkbox.
877 (org-insert-todo-heading nil))
878
879 ((org-in-item-p)
880 ;; Plain list. Yes, this gets a little complicated...
881 (let ((context (org-element-context)))
882 (if (or (eq 'plain-list (car context)) ; First item in list
883 (and (eq 'item (car context))
884 (not (eq (org-element-property :contents-begin context)
885 (org-element-property :contents-end context))))
886 ;; Element in list item, e.g. a link
887 (unpackaged/org-element-descendant-of 'item context))
888 ;; Non-empty item: Add new item.
889 (org-insert-item)
890 ;; Empty item: Close the list.
891 ;; TODO: Do this with org functions rather than operating
892 ;; on the text. Can't seem to find the right function.
893 (delete-region (line-beginning-position) (line-end-position))
894 (insert "\n"))))
895
896 ((when (fboundp 'org-inlinetask-in-task-p)
897 (org-inlinetask-in-task-p))
898 ;; Inline task: Don't insert a new heading.
899 (org-return))
900
901 ((org-at-table-p)
902 (cond ((save-excursion
903 (beginning-of-line)
904 ;; See `org-table-next-field'.
905 (cl-loop with end = (line-end-position)
906 for cell = (org-element-table-cell-parser)
907 always (equal (org-element-property :contents-begin cell)
908 (org-element-property :contents-end cell))
909 while (re-search-forward "|" end t)))
910 ;; Empty row: end the table.
911 (delete-region (line-beginning-position) (line-end-position))
912 (org-return))
913 (t
914 ;; Non-empty row: call `org-return'.
915 (org-return))))
916 (t
917 ;; All other cases: call `org-return'.
918 (org-return)))))
919
920;; org-fix-blank-lines (unpackaged)
921(defun unpackaged/org-fix-blank-lines (&optional prefix)
922 "Ensure that blank lines exist between headings and between headings and their contents.
923 With prefix, operate on whole buffer. Ensures that blank lines
924 exist after each headings's drawers."
925 (interactive "P")
926 (org-map-entries (lambda ()
927 (org-with-wide-buffer
928 ;; `org-map-entries' narrows the buffer, which prevents us
929 ;; from seeing newlines before the current heading, so we
930 ;; do this part widened.
931 (while (not (looking-back "\n\n" nil))
932 ;; Insert blank lines before heading.
933 (insert "\n")))
934 (let ((end (org-entry-end-position)))
935 ;; Insert blank lines before entry content
936 (forward-line)
937 (while (and (org-at-planning-p)
938 (< (point) (point-max)))
939 ;; Skip planning lines
940 (forward-line))
941 (while (re-search-forward org-drawer-regexp end t)
942 ;; Skip drawers. You might think that `org-at-drawer-p'
943 ;; would suffice, but for some reason it doesn't work
944 ;; correctly when operating on hidden text. This
945 ;; works, taken from `org-agenda-get-some-entry-text'.
946 (re-search-forward "^[ \t]*:END:.*\n?" end t)
947 (goto-char (match-end 0)))
948 (unless (or (= (point) (point-max))
949 (org-at-heading-p)
950 (looking-at-p "\n"))
951 (insert "\n"))))
952 t (if prefix
953 nil
954 'tree)))
955
956(defun hook--org-mode-fix-blank-lines ()
957 (when (eq major-mode 'org-mode)
958 (let ((current-prefix-arg 4)) ; Emulate C-u
959 (call-interactively 'unpackaged/org-fix-blank-lines))))
960(add-hook 'before-save-hook #'hook--org-mode-fix-blank-lines)
961
962(use-package org
963 :straight (:repo "https://code.orgmode.org/bzg/org-mode.git")
964 :init
965 (setq-default
966 org-directory "~/org" ; where to search for org files
967 ;; typesetting
968 org-hide-emphasis-markers t
969 org-fontify-whole-heading-line t
970 org-fontify-done-headline t
971 org-fontify-quote-and-verse-blocks t
972 org-src-fontify-natively t
973 org-ellipsis " ≡"
974 org-pretty-entities t
975 org-tags-column (- 0 fill-column (- (length org-ellipsis)))
976 ;; Source blocks
977 org-src-tab-acts-natively t
978 org-src-window-setup 'current-window
979 org-confirm-babel-evaluate nil
980 ;; Behavior
981 org-adapt-indentation t ; indent text after a header
982 org-catch-invisible-edits 'smart
983 org-special-ctrl-a/e t
984 org-special-ctrl-k t
985 org-imenu-depth 8 ; catch all headings
986 ;; Exporting
987 org-export-headline-levels 8 ; export all headings
988 org-export-with-smart-quotes t
989 org-export-with-sub-superscripts t
990 ;; Modules
991 org-modules '(;; default (commented if unused)
992 ;; bbdb
993 ;; bibtex
994 ;; docview
995 eww
996 ;; gnus
997 info
998 ;; irc
999 ;; mhe
1000 ;; rmail
1001 ;; w3m
1002 ;; extra stuff for me
1003 ;; habit ; track your consistency with habits
1004 ;; inlinetask ; tasks independent of outline hierarchy
1005 mouse ; additional mouse support
1006 ;; protocol ; intercept calls from emacsclient
1007 ;; man
1008 tempo ; templates
1009 )
1010 org-export-backends '(;; defaults
1011 ascii
1012 html
1013 latex
1014 odt
1015 ;; added by me
1016 man
1017 md
1018 )
1019 )
1020 :config
1021 (require 'org-tempo)
1022 (require 'ox-md)
1023 :bind (:map org-mode-map
1024 ("RET" . unpackaged/org-return-dwim)))
1025
1026(use-package goto-addr
1027 :straight nil
1028 :config
1029 (goto-address-mode +1))
1030
1031(use-package web-mode
1032 :mode (("\\.phtml\\'" . web-mode)
1033 ("\\.tpl\\.php\\'" . web-mode)
1034 ("\\.[agj]sp\\'" . web-mode)
1035 ("\\as[cp]x\\'" . web-mode)
1036 ("\\.erb\\'" . web-mode)
1037 ("\\.mustache\\'" . web-mode)
1038 ("\\.djhtml\\'" . web-mode)
1039 ("\\.html?\\'" . web-mode)))