208 lines
6.6 KiB
EmacsLisp
208 lines
6.6 KiB
EmacsLisp
(use-package org-mode
|
|
:bind
|
|
(("<f5> o" . 'org-mode)
|
|
:map org-mode-map
|
|
("C-," . nil)
|
|
("M-n" . org-metadown)
|
|
("M-p" . org-metaup)
|
|
("C-c C--" . org-ctrl-c-minus)
|
|
("C-c C-," . org-metaleft)
|
|
("C-c C-." . org-metaright)
|
|
;; ("C-j" . org-return)
|
|
;; ("C-m" . org-return-indent)
|
|
("C-c C-9" . org-mark-ring-goto)
|
|
("C-c C-/" . org-sparse-tree)
|
|
("M-w" . cp-copy-line-or-link)
|
|
("C-c C-]" . org-set-tags)
|
|
("C-M-x" . cp/eval-sexp)
|
|
("C-c C-o" . cp/org-open))
|
|
:config
|
|
;; (setq org-M-RET-may-split-line 'nil)
|
|
;; (add-hook 'org-mode-hook 'org-display-inline-images)
|
|
|
|
;; (defun cp-org-expand-all ()
|
|
;; (interactive)
|
|
;; ;; todo - define inner recursive function
|
|
;; (beginning-of-buffer)
|
|
;; ;; todo - check if we are on a heading
|
|
;; (org-forward-heading-same-level)
|
|
;; ())
|
|
(setq org-file-apps
|
|
'(("txt" . emacs)
|
|
("org" . emacs)
|
|
;; ("pdf" . zathura)
|
|
("\\(?:gif\\|jpe?g\\|png\\)" . "sxiv -f %s")
|
|
;; (t . "xdg-open %s")
|
|
|
|
("pdf" . system)
|
|
;; ("pdf" . "zathura %s")
|
|
;; (auto-mode . emacs)
|
|
;; (system . "xdg-open %s")
|
|
(system . "zathura %s")
|
|
;; (t . system)
|
|
)
|
|
org-todo-keywords '((sequence "TODO" "RESEARCH" "STARTED" "DONE"))
|
|
org-image-actual-width 400
|
|
org-cycle-include-plain-lists 'integrate
|
|
org-link-search-must-match-exact-headline nil
|
|
|
|
org-html-head
|
|
;; made to resemble Firefox's reader mode, dark setting
|
|
"<style type=text/css>
|
|
body {
|
|
margin: 40px auto;
|
|
max-width: 650px;
|
|
line-height: 1.6;
|
|
font-size: 18px;
|
|
color: #eeeeee !important;
|
|
padding: 0 10px;
|
|
background-color: #333333;
|
|
font-family: sans-serif;
|
|
}
|
|
h1,h2,h3 {
|
|
line-height: 1.2;
|
|
}
|
|
a,a:visited {
|
|
color: #07a;
|
|
}
|
|
img {
|
|
max-width: 80%;
|
|
height: auto;
|
|
width: auto\9; /* ie8 */
|
|
}
|
|
</style>"
|
|
|
|
;; ;; mix of motherfuckingwebsite.com + bettermotherfuckingwebsite.com + thebestmotherfucking.website
|
|
|
|
;; "<style type=text/css>
|
|
;; body {
|
|
;; margin: 40px auto;
|
|
;; max-width: 650px;
|
|
;; line-height: 1.6;
|
|
;; font-size: 18px;
|
|
;; color: #444;
|
|
;; padding: 0 10px;
|
|
;; background-color: #eeeeee;
|
|
;; font-family: sans-serif;
|
|
;; }
|
|
;; h1,h2,h3 {
|
|
;; line-height: 1.2;
|
|
;; }
|
|
;; a,a:visited {
|
|
;; color: #07a;
|
|
;; }
|
|
;; img {
|
|
;; max-width: 80%;
|
|
;; height: auto;
|
|
;; width: auto\9; /* ie8 */
|
|
;; }
|
|
;; </style>"
|
|
|
|
org-export-default-inline-image-rule
|
|
`(("https" .
|
|
,(format "\\.%s\\'"
|
|
(regexp-opt
|
|
'("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm"
|
|
"xpm" "pbm" "pgm" "ppm" "webp") t)))
|
|
("file" .
|
|
,(format "\\.%s\\'"
|
|
(regexp-opt
|
|
'("png" "jpeg" "jpg" "gif" "tiff" "tif" "xbm"
|
|
"xpm" "pbm" "pgm" "ppm" "webp") t))))) )
|
|
|
|
(defvar cp/org-heading-or-list-rx
|
|
'(and
|
|
;; headings
|
|
(zero-or-more "*")
|
|
(zero-or-more blank)
|
|
;; list items
|
|
(zero-or-one
|
|
(or "- " "+ " "* "
|
|
(and (one-or-more (char "0-9"))
|
|
(or ". " ") "))))
|
|
(zero-or-one (and "[" nonl "] "))))
|
|
|
|
(defun org-link-ahead-p (&optional link-type)
|
|
"Returns t if point is before an org-mode link, ignoring
|
|
whitespace and org-mode header and list syntax, else nil.
|
|
|
|
If LINK-TYPE is 'implicit, checks for an implicit link (one not
|
|
inside single or double brackets); otherwise, checks for links in
|
|
the form [[address][description]] and [[address]]."
|
|
(looking-at
|
|
(rx-to-string
|
|
(append cp/org-heading-or-list-rx
|
|
(if (eq link-type 'implicit)
|
|
'("http")
|
|
'("["))))))
|
|
|
|
(defun cp/org-open (&optional arg reference-buffer)
|
|
(interactive "P")
|
|
(save-excursion
|
|
(re-search-line
|
|
(rx-to-string
|
|
(append cp/org-heading-or-list-rx
|
|
'((or "[" "[[" "http")))))
|
|
(org-open-at-point arg reference-buffer)))
|
|
|
|
(defun cp-copy-line-or-link (prefix-arg)
|
|
"Copy address of org-mode link after point, ignoring whitespace,
|
|
link description (if any) and org-mode header and list syntax. If
|
|
not before a link, or with a prefix arg, call
|
|
`whole-line-or-region-kill-ring-save' instead.
|
|
|
|
BUG - improper behaviour with checkboxes.
|
|
2018-03-17T21:15:17+0530 - hopefully fixed now."
|
|
(interactive "P")
|
|
(let ((point-a (point)))
|
|
(cl-flet ((copy-to-closing-bracket
|
|
()
|
|
(let ((point-b (point)))
|
|
(re-search-forward "\\]")
|
|
(copy-region-as-kill point-b
|
|
(- (point) 1)))))
|
|
|
|
(if (save-excursion
|
|
(or (use-region-p)
|
|
prefix-arg
|
|
(re-search-line "\\[[-X ]\\]")))
|
|
(whole-line-or-region-kill-ring-save prefix-arg)
|
|
|
|
(cond ( ;; (org-link-ahead-p)
|
|
(re-search-line "\\[")
|
|
;; (if (looking-at "\\[")
|
|
;; (forward-char))
|
|
(forward-char)
|
|
(copy-to-closing-bracket)
|
|
(goto-char point-a))
|
|
|
|
( ;; (org-link-ahead-p 'implicit)
|
|
(re-search-line "http")
|
|
(backward-word)
|
|
(let ((point-b (point)))
|
|
(re-search-forward (rx (or eol (and printing " "))))
|
|
(copy-region-as-kill point-b
|
|
(point)))
|
|
(goto-char point-a))
|
|
|
|
;; TODO - org-previous-link will land you at the start
|
|
;; of the DESCRIPTION of the previous link, if it has
|
|
;; one, but to the user it will look like they are at
|
|
;; the start of the link. Add a case to handle this.
|
|
|
|
;; Does not work if there is an org TODO marker in a
|
|
;; header.
|
|
|
|
(t (whole-line-or-region-kill-ring-save prefix-arg)))))))
|
|
|
|
(defun cp/org-table-convert-tsv ()
|
|
(interactive)
|
|
(with-output-to-temp-buffer "cp/org-table-convert-tsv"
|
|
(->> (buffer-substring-no-properties (region-beginning) (region-end))
|
|
(replace-regexp-in-string "^| *" "")
|
|
(replace-regexp-in-string " *| *" " ")
|
|
(replace-regexp-in-string "^-.*$" "")))
|
|
(with-current-buffer "cp/org-table-convert-tsv"
|
|
(remove-hook 'before-save-hook 'delete-trailing-whitespace)
|
|
(write-file (read-from-minibuffer "Output filename: "))))
|