Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (add-to-list 'org-structure-template-alist
- '("scn" "#+BEGIN_SRC cn?n#+END_SRC"))
- ;; Function to indent code in org-mode
- (defun start-of-current-line-or-region ()
- "Return the point at the start of the current line or region."
- (save-excursion
- (if mark-active
- (progn
- (goto-char (region-beginning))
- (point-at-bol))
- (point-at-bol))))
- (defun end-of-current-line-or-region ()
- "Return the point at the end of the current line or region."
- (save-excursion
- (if mark-active
- (progn
- (goto-char (region-end))
- (point-at-eol))
- (point-at-eol))))
- (defun org-indent-code()
- (interactive)
- (org-edit-special)
- (save-excursion (save-restriction
- (mark-whole-buffer)
- (indent-region (start-of-current-line-or-region)
- (end-of-current-line-or-region))))
- (org-edit-src-exit)
- )
- ;; Indent plain lists that are copied
- (defun org-adjust-region (b e)
- "Readjust stuff in region according to the preceeding stuff."
- (interactive "r") ;; current region
- (save-excursion
- (let ((e (set-marker (make-marker) e))
- (_indent (lambda ()
- (insert ?n)
- (backward-char)
- (org-indent-line)
- (delete-char 1)))
- last-item-pos)
- (goto-char b)
- (beginning-of-line)
- (while (< (point) e)
- (indent-line-to 0)
- (cond
- ((looking-at "[[:space:]]*$")) ;; ignore empty lines
- ((org-at-heading-p)
- (error "Headings cannot be balanced (yet)."))
- ((org-at-item-p)
- (funcall _indent)
- (let ((struct (org-list-struct))
- (mark-active nil))
- (ignore-errors (org-list-indent-item-generic -1 t struct)))
- (setq last-item-pos (point)))
- ((org-at-block-p)
- (funcall _indent)
- (goto-char (plist-get (cadr (org-element-special-block-parser e nil)) :contents-end))
- (org-indent-line))
- (t (funcall _indent)))
- (forward-line))
- (when last-item-pos
- (goto-char last-item-pos)
- (org-list-repair)
- )))
- (org-fill-paragraph)
- )
- (defun org-adjust-region-yank1 ()
- ""
- (interactive)
- (if (org-in-src-block-p)
- (progn (save-excursion (yank 1)) (org-indent-code))
- (let ((beg (point))) (yank 1) (org-adjust-region beg (point)))))
- (defun org-copy-and-indent ()
- (interactive)
- (insert "+ Notes")
- (newline)
- (org-cycle)
- (insert "<scn")
- (org-cycle)
- (org-adjust-region-yank1)
- )
Add Comment
Please, Sign In to add comment