Emacs Left Hand Quick Commands

<2024-04-10 Wed>

  ;; KILL
  (global-set-key (kbd "C-1") 'kill-this-buffer)

  ;; MARK COMMANDS
  ;; URL: https://www.masteringemacs.org/article/fixing-mark-commands-transient-mark-mode
  (defun push-mark-no-activate ()
    "Pushes `point' to `mark-ring' and does not activate the region
           Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
    (interactive)
    (push-mark (point) t nil)
    (message "Pushed mark to ring"))

  (global-set-key (kbd "C-`") 'push-mark-no-activate)

  (defun jump-to-mark ()
    "Jumps to the local mark, respecting the `mark-ring' order.
          This is the same as using \\[set-mark-command] with the prefix argument."
    (interactive)
    (set-mark-command 1))
  (global-set-key (kbd "M-`") 'jump-to-mark)

  (defun exchange-point-and-mark-no-activate ()
    "Identical to \\[exchange-point-and-mark] but will not activate the region."
    (interactive)
    (exchange-point-and-mark)
    (deactivate-mark nil))
  (define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)

    (defun exchange-point-and-mark-no-activate ()
    "Identical to \\[exchange-point-and-mark] but will not activate the region."
    (interactive)
    (exchange-point-and-mark)
    (deactivate-mark nil))
  (define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)

  ;; JUMP OUT
  (defun jump-out-of-pair ()
    (interactive)
    (let ((found (search-forward-regexp "[])}\"'`*=]" nil t)))
      (when found
        (cond ((or (looking-back "\\*\\*" 2)
           (looking-back "``" 2)
           (looking-back "''" 2)
           (looking-back "==" 2))
             (forward-char))
            (t (forward-char 0))))))

  (global-set-key (kbd "M-1") 'jump-out-of-pair)

  ;; UNFILL
  (require 'unfill)
  (global-set-key (kbd "M-2") 'unfill-paragraph)

Most people, myself included, use transient-mark-mode (or just tmm), a great piece of kit that makes Emacs behave sanely by using visible regions like other editors. But tmm can get in the way of Emacs’s point

Return to Home