daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest Dec 18th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (add-to-list 'org-structure-template-alist
  2.                  '("scn" "#+BEGIN_SRC cn?n#+END_SRC"))
  3.  
  4.     ;; Function to indent code in org-mode
  5.     (defun start-of-current-line-or-region ()
  6.       "Return the point at the start of the current line or region."
  7.       (save-excursion
  8.         (if mark-active
  9.             (progn
  10.               (goto-char (region-beginning))
  11.               (point-at-bol))
  12.           (point-at-bol))))
  13.     (defun end-of-current-line-or-region ()
  14.       "Return the point at the end of the current line or region."
  15.       (save-excursion
  16.         (if mark-active
  17.             (progn
  18.               (goto-char (region-end))
  19.               (point-at-eol))
  20.           (point-at-eol))))
  21.     (defun org-indent-code()
  22.       (interactive)
  23.       (org-edit-special)
  24.       (save-excursion (save-restriction
  25.       (mark-whole-buffer)
  26.       (indent-region (start-of-current-line-or-region)
  27.                      (end-of-current-line-or-region))))
  28.       (org-edit-src-exit)
  29.       )
  30.  
  31.     ;; Indent plain lists that are copied
  32.     (defun org-adjust-region (b e)
  33.       "Readjust stuff in region according to the preceeding stuff."
  34.       (interactive "r") ;; current region
  35.       (save-excursion
  36.         (let ((e (set-marker (make-marker) e))
  37.               (_indent (lambda ()
  38.                          (insert ?n)
  39.                          (backward-char)
  40.                          (org-indent-line)
  41.                          (delete-char 1)))
  42.               last-item-pos)
  43.           (goto-char b)
  44.           (beginning-of-line)
  45.           (while (< (point) e)
  46.             (indent-line-to 0)
  47.             (cond
  48.              ((looking-at "[[:space:]]*$")) ;; ignore empty lines
  49.              ((org-at-heading-p)
  50.               (error "Headings cannot be balanced (yet)."))
  51.              ((org-at-item-p)
  52.               (funcall _indent)
  53.               (let ((struct (org-list-struct))
  54.                     (mark-active nil))
  55.                 (ignore-errors (org-list-indent-item-generic -1 t struct)))
  56.               (setq last-item-pos (point)))
  57.              ((org-at-block-p)
  58.               (funcall _indent)
  59.               (goto-char (plist-get (cadr (org-element-special-block-parser e nil)) :contents-end))
  60.               (org-indent-line))
  61.              (t (funcall _indent)))
  62.             (forward-line))
  63.           (when last-item-pos
  64.             (goto-char last-item-pos)
  65.             (org-list-repair)
  66.             )))
  67.             (org-fill-paragraph)
  68.             )
  69.  
  70.  
  71. (defun org-adjust-region-yank1 ()
  72.     ""
  73.       (interactive)
  74.       (if (org-in-src-block-p)
  75.       (progn (save-excursion (yank 1)) (org-indent-code))
  76.       (let ((beg (point))) (yank 1) (org-adjust-region beg (point)))))
  77.  
  78. (defun org-copy-and-indent ()
  79.   (interactive)
  80.   (insert "+ Notes")
  81.   (newline)
  82.   (org-cycle)
  83.   (insert "<scn")
  84.   (org-cycle)
  85.   (org-adjust-region-yank1)
  86. )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top