insert-pair.el 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ;;; insert-pair.el --- Commands for inserting pairs of characters
  2. ;; Copyright © 2015 Alex Kost
  3. ;; Author: Alex Kost <alezost@gmail.com>
  4. ;; Created: 12 Jan 2015
  5. ;; Version: 0.1
  6. ;; URL: https://github.com/alezost/insert-pair.el
  7. ;; Keywords: convenience
  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 of the License, or
  11. ;; (at your option) any later version.
  12. ;; This program is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; This package provides commands analogous to `insert-parentheses' but
  20. ;; for inserting other pairs of characters.
  21. ;;
  22. ;; These commands have the following names:
  23. ;; `insert-pair-curly-brackets', `insert-pair-double-quotations' and so
  24. ;; on (see `insert-pair-specifications' variable). The commands may be
  25. ;; used in the same manner as the built-in `insert-parentheses' command.
  26. ;;; Code:
  27. ;;;###autoload
  28. (defvar insert-pair-specifications
  29. '(("square-brackets" ?[ ?])
  30. ("curly-brackets" ?{ ?})
  31. ("angle-brackets" ?< ?>)
  32. ("single-quotations" ?' ?')
  33. ("double-quotations" ?\" ?\")
  34. ("left-right-single-quotations" ?‘ ?’)
  35. ("left-right-double-quotations" ?“ ?”)
  36. ("angle-quotations" ?« ?»)
  37. ("grave-accents" ?` ?`)
  38. ("grave-accent-quotation" ?` ?')
  39. ("top-corners" ?⌜ ?⌝)
  40. ("bottom-corners" ?⌞ ?⌟))
  41. "List of pair specifications used to generate commands.")
  42. (defmacro insert-pair-define-command (name open close)
  43. "Define command for inserting a pair of OPEN and CLOSE characters.
  44. The command name is `insert-pair-NAME'."
  45. `(defun ,(intern (concat "insert-pair-" name)) (&optional arg)
  46. ,(format "Similar to `insert-parentheses', except it inserts %c%c."
  47. open close)
  48. (interactive "P")
  49. (insert-pair arg ,open ,close)))
  50. (dolist (spec insert-pair-specifications)
  51. (eval `(insert-pair-define-command
  52. ,(nth 0 spec)
  53. ,(nth 1 spec)
  54. ,(nth 2 spec))))
  55. ;;;###autoload(dolist (spec insert-pair-specifications)
  56. ;;;###autoload (autoload (intern (concat "insert-pair-" (car spec)))
  57. ;;;###autoload "insert-pair" nil t))
  58. (provide 'insert-pair)
  59. ;;; insert-pair.el ends here