al-text.el 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ;;; al-text.el --- Additional functionality related to text editing
  2. ;; Copyright © 2014-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (defun al/beginning-of-buffer ()
  15. (goto-char (point-min)))
  16. (defun al/show-trailing-whitespace ()
  17. (setq-local show-trailing-whitespace t))
  18. (defun al/no-truncate-lines ()
  19. (setq-local truncate-lines nil))
  20. (defun al/inhibit-field-motion ()
  21. (setq-local inhibit-field-text-motion t))
  22. (defun al/bar-cursor-type ()
  23. (setq-local cursor-type 'bar))
  24. (defun al/hbar-cursor-type ()
  25. (setq-local cursor-type 'hbar))
  26. (defun al/no-syntactic-font-lock ()
  27. (setq-local font-lock-keywords-only t))
  28. (defun al/set-comment-column ()
  29. (setq-local comment-column 32))
  30. (defmacro al/modify-syntax (table-name &rest specs)
  31. "Update syntax table according to SPECS.
  32. TABLE-NAME is a name (unquoted symbol) of a syntax table variable.
  33. SPECS are (CHAR NEWENTRY) elements. See `modify-syntax-entry'
  34. for details."
  35. (declare (indent 1))
  36. (let ((table-var (make-symbol "table")))
  37. `(al/with-check
  38. :var ',table-name
  39. (let ((,table-var (symbol-value ',table-name)))
  40. ,@(mapcar
  41. (lambda (spec)
  42. (pcase spec
  43. (`(,char ,entry)
  44. `(modify-syntax-entry ,char ,entry ,table-var))))
  45. specs)))))
  46. (defmacro al/modify-page-break-syntax (table-name)
  47. "Set non-whitespace syntax for ^L in syntax table TABLE-NAME.
  48. Page break should not belong to whitespace syntax, because
  49. `back-to-indentation' moves the point after ^L character which is not good.
  50. Also it (default syntax) breaks `indent-guide-mode'."
  51. `(al/modify-syntax ,table-name (?\f "> ")))
  52. (provide 'al-text)
  53. ;;; al-text.el ends here