litorgy-ui.el 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ;;; litorgy-ui.el --- UI elements for litorgy
  2. ;; Copyright (C) 2009 Eric Schulte, Dan Davison, Austin F. Frank
  3. ;; Author: Eric Schulte, Dan Davison, Austin F. Frank
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 0.01
  7. ;;; License:
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Commentary:
  23. ;; UI elements of litorgy
  24. ;; - code folding
  25. ;; - marking working code blocks
  26. ;;; Code:
  27. (require 'litorgy)
  28. (defadvice org-cycle (around litorgy-ui-org-cycle-src-block activate)
  29. "Intercept calls to org-cycle to toggle the visibility of a source code block."
  30. (if (save-excursion
  31. (beginning-of-line 1)
  32. (looking-at litorgy-src-block-regexp))
  33. (litorgy-ui-src-block-cycle)
  34. ad-do-it))
  35. (defun litorgy-ui-src-block-cycle ()
  36. "Cycle the visibility of the current source code block"
  37. (interactive)
  38. ;; should really do this once in an (org-mode hook)
  39. (add-to-invisibility-spec '(litorgy-ui . t))
  40. (save-excursion
  41. (beginning-of-line)
  42. (if (re-search-forward litorgy-src-block-regexp nil t)
  43. (let ((start (- (match-beginning 4) 1)) ;; beginning of body
  44. (end (match-end 0))) ;; end of entire body
  45. (if (memq t (mapcar (lambda (overlay)
  46. (eq (overlay-get overlay 'invisible) 'litorgy-ui))
  47. (overlays-at start)))
  48. (remove-overlays start end 'invisible 'litorgy-ui)
  49. (overlay-put (make-overlay start end) 'invisible 'litorgy-ui)))
  50. (error "not looking at source code block"))))
  51. (provide 'litorgy-ui)
  52. ;;; litorgy-ui ends here