Skip to content

Commit

Permalink
Add fix for volrath/treepy.el#9
Browse files Browse the repository at this point in the history
  • Loading branch information
dsedivec committed Jun 19, 2021
1 parent d98848c commit d6b4a74
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ upgraded."
;; installed.)
(require 'dash)

;; Fix for https://github.com/volrath/treepy.el/issues/9, necessary
;; for treepy-remove to work right.
(my:load-recipes 'treepy-remove-fix)

;; Don't take up mode line space if encoding is unspecified or Unicode-ish.
(unless
(my:treepy-edit-mode-line-var
Expand Down
33 changes: 33 additions & 0 deletions recipes/treepy-remove-fix.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;; -*- lexical-binding: t; -*-

;; Fix for https://github.com/volrath/treepy.el/issues/9.

(require 'el-patch)

(el-patch-feature treepy)

(with-eval-after-load 'treepy
(el-patch-defun treepy-remove (loc)
"Remove the node at LOC.
Return the loc that would have preceded it in a depth-first
walk."
(treepy--with-loc loc (context pnodes ppath l r)
(if (not context)
(error "Remove at top")
(if (> (length l) 0)
(let ((nloc (treepy--with-meta (cons (car l)
(treepy--context-assoc context
':l (cdr l)
':changed? t))
(treepy--meta loc)))
(el-patch-remove (child nil)))
(el-patch-remove
(while (setq child (and (treepy-branch-p nloc) (treepy-children nloc)))
(setq nloc (treepy-rightmost child))))
nloc)
(treepy--with-meta
(cons (treepy-make-node loc (car pnodes) r)
(and ppath (treepy--context-assoc context ':changed? t)))
(treepy--meta loc))))))

(el-patch-validate 'treepy-remove 'defun t))

0 comments on commit d6b4a74

Please sign in to comment.