Skip to content

Commit

Permalink
[Core-Utils] Add string-trim-right implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Miller committed Aug 30, 2023
1 parent 7a36a3c commit 3cd2a0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/elisp/treemacs-core-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ Used in `treemacs-is-node-expanded?'")
(substring ,path 0 -1)
,path))))

(define-inline treemacs-string-trim-right (string)
"Trim STRING of trailing string matching REGEXP.
Same as the builtin `string-trim-right', but re-implemented here for Emacs 27."
(declare (side-effect-free t))
(inline-letevals (string)
(inline-quote
(let ((i (string-match-p "\\(?:[ \t\n\r]+\\)\\'" ,string)))
(if i (substring ,string 0 i) ,string)))))

(define-inline treemacs--prefix-arg-to-recurse-depth (arg)
"Translates prefix ARG into a number.
Used for depth-based expansion of nodes - a numeric prefix will translate to
Expand Down
2 changes: 1 addition & 1 deletion src/elisp/treemacs-git-commit-diff-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Look for the PROJECT either in BUFFER or the local treemacs buffer."
:on-success
(when (buffer-live-p buffer)
(-let [out (-> (pfuture-callback-output)
(string-trim-right)
(treemacs-string-trim-right)
(read))]
(with-current-buffer buffer
(if out
Expand Down
2 changes: 1 addition & 1 deletion src/extra/treemacs-magit.el
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Relevant for integrating with `treemacs-git-commit-diff-mode'.")
:directory path
:on-success
(-let [out (-> (pfuture-callback-output)
(string-trim-right)
(treemacs-string-trim-right)
(read))]
(treemacs-run-in-every-buffer
(-when-let* ((project (treemacs--find-project-for-path path))
Expand Down

0 comments on commit 3cd2a0d

Please sign in to comment.