func.el 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ;;; func --- useful functions
  2. ;;; Commentary:
  3. ;;; Useful editing functions
  4. ;;; Code:
  5. ;; Comment line. Only useful on Emacs version < 25
  6. (defun comment-line ()
  7. "Comment or uncomment the current line. Your cursor doesn't move."
  8. (interactive)
  9. (comment-or-uncomment-region (point-at-bol) (point-at-eol)))
  10. (global-set-key (kbd "C-x C-;") 'comment-line)
  11. (defun backward-delete-word-no-kill-ring (arg)
  12. "Delete characters backward until encountering the beginning of a word.
  13. With argument ARG, do this that many times."
  14. (interactive "p")
  15. (delete-region (point) (progn (backward-word arg) (point))))
  16. (defun forward-delete-word-no-kill-ring (arg)
  17. "Delete characters forward until encountering the beginning of a word.
  18. With argument ARG, do this that many times."
  19. (interactive "p")
  20. (delete-region (point) (progn (forward-word arg) (point))))
  21. (defun vsplit-last-buffer ()
  22. (interactive)
  23. (split-window-vertically)
  24. (other-window 1 nil)
  25. (switch-to-next-buffer))
  26. (defun hsplit-last-buffer ()
  27. (interactive)
  28. (split-window-horizontally)
  29. (other-window 1 nil)
  30. (switch-to-next-buffer))
  31. (global-set-key (kbd "C-x 2") 'vsplit-last-buffer)
  32. (global-set-key (kbd "C-x 3") 'hsplit-last-buffer)
  33. (defun kill-and-delete-window ()
  34. (interactive)
  35. (kill-buffer)
  36. (if (equal 1 (length (window-list)))
  37. nil
  38. (delete-window)))
  39. (defun beginning-of-line-edit ()
  40. "Move to the beginnging of the line and switch to edit mode."
  41. (interactive)
  42. (move-beginning-of-line nil)
  43. (modalka-mode -1))
  44. (defun end-of-line-edit ()
  45. "Move to the end of the line and switch to edit mode."
  46. (interactive)
  47. (move-end-of-line nil)
  48. (modalka-mode -1))
  49. (defun forward-word-edit (&optional n)
  50. "N is how many words you wish to jump.
  51. Jump the word and switch to edit mode."
  52. (interactive "p\n")
  53. (forward-word n)
  54. (modalka-mode -1))
  55. (defun backward-word-edit (&optional n)
  56. "N is how many words you wish to jump.
  57. Jump the word backwards and switch to edit mode."
  58. (interactive "p\n")
  59. (backward-word n)
  60. (modalka-mode -1))
  61. (defun replace-char ()
  62. "Replace the character underneath the cursor."
  63. (interactive)
  64. (let ((c (read-key)))
  65. (delete-char 1)
  66. (insert c)))
  67. (defun iy-go-to-char-correctly (n char)
  68. "N is the number of occurances, CHAR is the character you wish to goto.
  69. This function fixes a flaw that the original has with not landing directly on the char you pick."
  70. (interactive "p\ncGo to char: ")
  71. (iy-go-to-char n char)
  72. (backward-char))
  73. (defun delete-forward-word-edit (&optional n)
  74. "N is how many words you wish to delete.
  75. Delete the word forwards and switch to edit mode."
  76. (interactive "p\n")
  77. (forward-delete-word-no-kill-ring n)
  78. (modalka-mode -1))
  79. (defun delete-backward-word-edit (&optional n)
  80. "N is how many words you wish to delete.
  81. Delete the word backwards and switch to edit mode."
  82. (interactive "p\n")
  83. (backward-delete-word-no-kill-ring n)
  84. (modalka-mode -1))
  85. (defun zap-to-char-edit (arg char)
  86. "ARG is how many characters you wish to delete, CHAR is the character.
  87. Delete to character and switch to edit mode."
  88. (interactive (list (prefix-numeric-value current-prefix-arg)
  89. (read-char "Zap to char: " t)))
  90. (zap-to-char arg char)
  91. (modalka-mode -1))
  92. (provide 'func)
  93. ;;; func.el ends here