Skip to content
Browse files

Add new my/begin-end-example, begin-end-src-emacs-lisp, begin-end-src…

  • Loading branch information
smiller committed Feb 7, 2015
1 parent 3548ff8 commit b622482b0a680c8b55091b687e3c96cfa6facf8d
Showing with 49 additions and 7 deletions.
  1. +3 −0 mode-hooks.el
  2. +19 −7 mods-org.el
  3. +27 −0 test/mods-org-test.el
@@ -5,6 +5,9 @@
(set-input-method "TeX")
(define-key org-mode-map (kbd "M-s M-q") 'my/begin-end-quote)
(define-key org-mode-map (kbd "M-s M-v") 'my/begin-end-verse)
(define-key org-mode-map (kbd "M-s M-x") 'my/begin-end-example)
(define-key org-mode-map (kbd "M-s M-e") 'my/begin-end-src-emacs-lisp)
(define-key org-mode-map (kbd "M-s M-r") 'my/begin-end-src-ruby)

(add-hook 'text-mode-hook 'my-text-mode-hook)
@@ -29,26 +29,38 @@

(defun my/begin-end-quote ()
(my/begin-end "quote"))
(my/begin-end "quote" "quote"))

(defun my/begin-end-verse ()
(my/begin-end "verse"))
(my/begin-end "verse" "verse"))

(defun my/begin-end (variant)
(defun my/begin-end-example ()
(my/begin-end "example" "example"))

(defun my/begin-end-src-emacs-lisp ()
(my/begin-end "src emacs-lisp" "src"))

(defun my/begin-end-src-ruby ()
(my/begin-end "src ruby" "src"))

(defun my/begin-end (begin-tag end-tag)
(let ((cited-string "\n"))
(when (use-region-p)
(setq cited-string
(my/fix-formatting (buffer-substring-no-properties (region-beginning) (region-end))))
(my/remove-old-citation-formatting (buffer-substring-no-properties (region-beginning) (region-end))))
(delete-region (region-beginning) (region-end)))
(insert "#+begin_" variant "\n"
(insert "#+begin_" begin-tag "\n"
"#+end_" variant "\n"))
"#+end_" end-tag "\n"))
(unless (use-region-p)
(forward-line -2)))

(defun my/fix-formatting (str)
(defun my/remove-old-citation-formatting (str)
(if (string= (substring str 0 2) "> ")
(replace-regexp-in-string "^> " " "
@@ -100,6 +100,33 @@
"#+begin_verse\n count > 42\n#+end_verse\n")))

(ert-deftest test-begin-end-example ()
"Tests begin-end-example"
(should (string= (with-temp-buffer
(insert "exemplaria\ninter alia\n")
"#+begin_example\nexemplaria\ninter alia\n#+end_example\n")))

(ert-deftest test-begin-end-src-emacs-lisp ()
"Tests begin-end-src-emacs-lisp"
(should (string= (with-temp-buffer
(insert "(defun my/begin-end-example\n(interactive)\n(my/begin-end \"example\"))\n")
"#+begin_src emacs-lisp\n(defun my/begin-end-example\n(interactive)\n(my/begin-end \"example\"))\n#+end_src\n")))

(ert-deftest test-begin-end-src-ruby ()
"Tests begin-end-src-ruby"
(should (string= (with-temp-buffer
(insert "class User < ActiveRecord::Base\n include Permissions\n")
"#+begin_src ruby\nclass User < ActiveRecord::Base\n include Permissions\n#+end_src\n")))

(defun select-region ()
(goto-char (point-min))
(set-mark-command nil)

0 comments on commit b622482

Please sign in to comment.
You can’t perform that action at this time.