underline.el 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ;;; underline.el --- insert/remove underlining (done by overstriking) in Emacs
  2. ;; Copyright (C) 1985, 2001-2012 Free Software Foundation, Inc.
  3. ;; Maintainer: FSF
  4. ;; Keywords: wp
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; This package deals with the primitive form of underlining
  18. ;; consisting of prefixing each character with "_\^h". The entry
  19. ;; point `underline-region' performs such underlining on a region.
  20. ;; The entry point `ununderline-region' removes it.
  21. ;;; Code:
  22. ;;;###autoload
  23. (defun underline-region (start end)
  24. "Underline all nonblank characters in the region.
  25. Works by overstriking underscores.
  26. Called from program, takes two arguments START and END
  27. which specify the range to operate on."
  28. (interactive "*r")
  29. (save-excursion
  30. (let ((end1 (make-marker)))
  31. (move-marker end1 (max start end))
  32. (goto-char (min start end))
  33. (while (< (point) end1)
  34. (or (looking-at "[_\^@- ]")
  35. (insert "_\b"))
  36. (forward-char 1)))))
  37. ;;;###autoload
  38. (defun ununderline-region (start end)
  39. "Remove all underlining (overstruck underscores) in the region.
  40. Called from program, takes two arguments START and END
  41. which specify the range to operate on."
  42. (interactive "*r")
  43. (save-excursion
  44. (let ((end1 (make-marker)))
  45. (move-marker end1 (max start end))
  46. (goto-char (min start end))
  47. (while (re-search-forward "_\b\\|\b_" end1 t)
  48. (delete-char -2)))))
  49. (provide 'underline)
  50. ;;; underline.el ends here