Permalink
Browse files

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

…-ruby
  • 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
View
@@ -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)
View
@@ -29,26 +29,38 @@
(defun my/begin-end-quote ()
(interactive)
(my/begin-end "quote"))
(my/begin-end "quote" "quote"))
(defun my/begin-end-verse ()
(interactive)
(my/begin-end "verse"))
(my/begin-end "verse" "verse"))
(defun my/begin-end (variant)
(defun my/begin-end-example ()
(interactive)
(my/begin-end "example" "example"))
(defun my/begin-end-src-emacs-lisp ()
(interactive)
(my/begin-end "src emacs-lisp" "src"))
(defun my/begin-end-src-ruby ()
(interactive)
(my/begin-end "src ruby" "src"))
(defun my/begin-end (begin-tag end-tag)
(interactive)
(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"
cited-string
"#+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)
(interactive)
(if (string= (substring str 0 2) "> ")
(replace-regexp-in-string "^> " " "
View
@@ -100,6 +100,33 @@
(buffer-string))
"#+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")
(select-region)
(my/begin-end-example)
(buffer-string))
"#+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")
(select-region)
(my/begin-end-src-emacs-lisp)
(buffer-string))
"#+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")
(select-region)
(my/begin-end-src-ruby)
(buffer-string))
"#+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.