From 5c2c9a50da3a3f534842ffe95a49fe990000a072 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Tue, 6 Jan 2026 21:25:57 +0100 Subject: Update markdown, rust and yasnippet --- .emacs.d/lisp/markdown-mode.el | 95 ++++++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 27 deletions(-) (limited to '.emacs.d/lisp/markdown-mode.el') diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 671210e..77f9bf5 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el @@ -187,12 +187,10 @@ fewer than six nested heading levels are used." :safe 'natnump :package-version '(markdown-mode . "2.4")) -(defcustom markdown-asymmetric-header nil +(defcustom markdown-asymmetric-header t "Determines if atx header style will be asymmetric. Set to a non-nil value to use asymmetric header styling, placing -header markup only at the beginning of the line. By default, -balanced markup will be inserted at the beginning and end of the -line around the header title." +header markup only at the beginning of the line." :group 'markdown :type 'boolean) @@ -2612,7 +2610,11 @@ Return the point at the end when a list item was found at the original point. If the point is not in a list item, do nothing." (let (indent) (forward-line) - (setq indent (current-indentation)) + ;; #904 consider a space indentation and tab indentation case + (save-excursion + (let ((pos (point))) + (back-to-indentation) + (setq indent (- (point) pos)))) (while (cond ;; Stop at end of the buffer. @@ -2902,7 +2904,8 @@ data. See `markdown-inline-code-at-point-p' for inline code." (defun markdown-heading-at-point (&optional pos) "Return non-nil if there is a heading at the POS. Set match data for `markdown-regex-header'." - (let ((match-data (get-text-property (or pos (point)) 'markdown-heading))) + (let* ((p (or pos (if (and (eolp) (>= (point) 2)) (1- (point)) (point)))) + (match-data (get-text-property p 'markdown-heading))) (when match-data (set-match-data match-data) t))) @@ -9321,6 +9324,37 @@ position." (require 'edit-indirect nil t) (defvar edit-indirect-guess-mode-function) (defvar edit-indirect-after-commit-functions) +(defvar edit-indirect--overlay) +(declare-function edit-indirect-commit "edit-indirect") +(declare-function edit-indirect--commit "edit-indirect") + +(defvar-local markdown--edit-indirect-committed-position nil) + +(defun markdown--edit-indirect-save-committed-position () + "Save where editing is committed in a local variable in the parent buffer." + (if-let* ((parent-buffer (overlay-buffer edit-indirect--overlay)) + ((with-current-buffer parent-buffer + (derived-mode-p 'markdown-mode))) + (pos (cons (line-number-at-pos) (current-column)))) + (with-current-buffer parent-buffer + (setq markdown--edit-indirect-committed-position pos)))) + +(with-eval-after-load 'edit-indirect + (advice-add #'edit-indirect--commit :after #'markdown--edit-indirect-save-committed-position)) + +(defun markdown--edit-indirect-move-to-committed-position () + "Move the point in the code block corresponding to the saved committed position." + (when-let* ((pos markdown--edit-indirect-committed-position) + (bounds (markdown-get-enclosing-fenced-block-construct)) + (fence-begin (nth 0 bounds))) + (goto-char fence-begin) + (let ((block-indentation (current-indentation))) + (forward-line (car pos)) + (move-to-column (+ block-indentation (cdr pos))))) + (setq markdown--edit-indirect-committed-position nil)) + +(with-eval-after-load 'edit-indirect + (advice-add #'edit-indirect-commit :after #'markdown--edit-indirect-move-to-committed-position)) (defun markdown--edit-indirect-after-commit-function (beg end) "Corrective logic run on code block content from lines BEG to END. @@ -9342,18 +9376,24 @@ at the END of code blocks." (interactive) (save-excursion (if (fboundp 'edit-indirect-region) - (let* ((bounds (markdown-get-enclosing-fenced-block-construct)) - (begin (and bounds (not (null (nth 0 bounds))) (goto-char (nth 0 bounds)) (line-beginning-position 2))) - (end (and bounds(not (null (nth 1 bounds))) (goto-char (nth 1 bounds)) (line-beginning-position 1)))) - (if (and begin end) - (let* ((indentation (and (goto-char (nth 0 bounds)) (current-indentation))) - (lang (markdown-code-block-lang)) - (mode (or (and lang (markdown-get-lang-mode lang)) - markdown-edit-code-block-default-mode)) - (edit-indirect-guess-mode-function - (lambda (_parent-buffer _beg _end) - (funcall mode))) - (indirect-buf (edit-indirect-region begin end 'display-buffer))) + (if-let* ((bounds (markdown-get-enclosing-fenced-block-construct)) + (fence-begin (nth 0 bounds)) + (fence-end (nth 1 bounds))) + (let* ((original-line (line-number-at-pos)) + (original-column (current-column)) + (begin (progn (goto-char fence-begin) (line-beginning-position 2))) + (line (max 0 (- original-line (line-number-at-pos) 1))) + (indentation (current-indentation)) + (column (max 0 (- original-column indentation))) + (end (progn (goto-char fence-end) (line-beginning-position 1))) + (lang (markdown-code-block-lang)) + (mode (or (and lang (markdown-get-lang-mode lang)) + markdown-edit-code-block-default-mode)) + (edit-indirect-guess-mode-function + (lambda (_parent-buffer _beg _end) + (funcall mode))) + (indirect-buf (edit-indirect-region begin end 'display-buffer))) + (with-current-buffer indirect-buf ;; reset `sh-shell' when indirect buffer (when (and (not (member system-type '(ms-dos windows-nt))) (member mode '(shell-script-mode sh-mode)) @@ -9361,16 +9401,17 @@ at the END of code blocks." (mapcar (lambda (e) (symbol-name (car e))) sh-ancestor-alist) '("csh" "rc" "sh")))) - (with-current-buffer indirect-buf - (sh-set-shell lang))) + (sh-set-shell lang)) (when (> indentation 0) ;; un-indent in edit-indirect buffer - (with-current-buffer indirect-buf - (indent-rigidly (point-min) (point-max) (- indentation))))) - (user-error "Not inside a GFM or tilde fenced code block"))) + (indent-rigidly (point-min) (point-max) (- indentation))) + (goto-char (point-min)) + (forward-line line) + (move-to-column column))) + (user-error "Not inside a GFM or tilde fenced code block")) (when (y-or-n-p "Package edit-indirect needed to edit code blocks. Install it now? ") - (progn (package-refresh-contents) - (package-install 'edit-indirect) - (markdown-edit-code-block)))))) + (package-refresh-contents) + (package-install 'edit-indirect) + (markdown-edit-code-block))))) ;;; Table Editing ============================================================= @@ -10522,7 +10563,7 @@ rows and columns and the column alignment." (define-key map (kbd "SPC") #'scroll-up-command) (define-key map (kbd ">") #'end-of-buffer) (define-key map (kbd "<") #'beginning-of-buffer) - (define-key map (kbd "q") #'kill-this-buffer) + (define-key map (kbd "q") #'kill-current-buffer) (define-key map (kbd "?") #'describe-mode) map) "Keymap for `markdown-view-mode'.") -- cgit v1.3