diff options
Diffstat (limited to 'modules/custom-line-paragraph.el')
| -rw-r--r-- | modules/custom-line-paragraph.el | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/modules/custom-line-paragraph.el b/modules/custom-line-paragraph.el index 2cbcecc16..d29d4125b 100644 --- a/modules/custom-line-paragraph.el +++ b/modules/custom-line-paragraph.el @@ -1,4 +1,4 @@ -;;; custom-line-paragraph.el --- -*- coding: utf-8; lexical-binding: t; -*- +;;; custom-line-paragraph.el --- Line and paragraph editing commands -*- coding: utf-8; lexical-binding: t; -*- ;; Author: Craig Jennings <c@cjennings.net> ;; ;;; Commentary: @@ -14,16 +14,9 @@ ;; Runtime requires: keybindings (expand-region on demand via declare-function). ;; Direct test load: yes (requires keybindings explicitly). ;; -;; This module provides the following line and paragraph manipulation utilities: -;; -;; - joining lines in a region or the current line with the previous one -;; - joining separate lines into a single paragraph -;; - duplicating lines or regions (optional commenting) -;; - removing duplicate lines -;; - removing lines containing specific text -;; - underlining text with a custom character -;; -;; Bound to keymap prefix C-; l +;; Line and paragraph transforms under C-; l: join, duplicate, delete matching +;; lines, remove duplicates, and underline text. Commands operate on the active +;; region when present and otherwise on the current line or paragraph. ;; ;;; Code: @@ -173,5 +166,36 @@ If the line is empty or contains only whitespace, abort with a message." "C-; l r" "remove matching" "C-; l u" "underscore line")) +;; --- delimiter jump (formerly in custom-misc.el) --- +(defun cj/jump-to-matching-paren () + "Jump to the matching delimiter if point is on (or just after) one. +If not on a delimiter, show a message. Respects the current syntax table." + (interactive) + (let* ((ca (char-after)) + (cb (char-before)) + ;; Check if on opening paren + (open-p (and ca (eq (char-syntax ca) ?\())) + ;; Check if on or just after closing paren + (close-p (or (and ca (eq (char-syntax ca) ?\))) + (and cb (eq (char-syntax cb) ?\)))))) + (cond + ;; Jump forward from opening + (open-p + (condition-case err + (forward-sexp) + (scan-error + (message "No matching delimiter: %s" (error-message-string err))))) + ;; Jump backward from closing + (close-p + (condition-case err + (backward-sexp) + (scan-error + (message "No matching delimiter: %s" (error-message-string err))))) + ;; Not on delimiter + (t + (message "Point is not on a delimiter."))))) + +(cj/register-command ")" #'cj/jump-to-matching-paren "jump to paren") + (provide 'custom-line-paragraph) ;;; custom-line-paragraph.el ends here. |
