[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote d1ee270784 3/6: Add denote--replace-consecutive-
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote d1ee270784 3/6: Add denote--replace-consecutive-token-characters and use it in denote-sluggify |
Date: |
Thu, 18 Jan 2024 09:57:42 -0500 (EST) |
branch: externals/denote
commit d1ee2707848c7c14d5d601566b642e961f90940b
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Add denote--replace-consecutive-token-characters and use it in
denote-sluggify
---
denote.el | 34 ++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/denote.el b/denote.el
index e3873cf3b7..9a986d5ad7 100644
--- a/denote.el
+++ b/denote.el
@@ -667,18 +667,36 @@ leading and trailing hyphen."
"-\\{2,\\}" "-"
(replace-regexp-in-string "_\\|\s+" "-" str))))
+(defun denote--replace-consecutive-token-characters (str)
+ "Replace consecutive characters with a single one in STR.
+Spaces, underscores and equal signs are replaced with a single
+one in str."
+ (replace-regexp-in-string
+ "-\\{2,\\}" "-"
+ (replace-regexp-in-string
+ "_\\{2,\\}" "_"
+ (replace-regexp-in-string
+ "=\\{2,\\}" "=" str))))
+
(defun denote-sluggify (component str)
"Make STR an appropriate slug for file name COMPONENT.
Apply the function specified in `denote-file-name-slug-function'
-to COMPONENT which is one of `title', `signature', `keyword'."
- (let ((slug-function (alist-get component denote-file-name-slug-functions)))
- (cond ((eq component 'title)
- (funcall (or slug-function #'denote-sluggify-title) str))
- ((eq component 'keyword)
- (funcall (or slug-function #'denote-sluggify-keyword) str))
- ((eq component 'signature)
- (funcall (or slug-function #'denote-sluggify-signature) str)))))
+to COMPONENT which is one of `title', `signature', `keyword'. If
+the resulting string still contains consecutive -,_ or =, they
+are replaced by a single occurence of the character. If
+COMPONENT is `keyword', remove underscores from STR as they are
+used as the keywords separator in file names."
+ (let* ((slug-function (alist-get component denote-file-name-slug-functions))
+ (str-slug (cond ((eq component 'title)
+ (funcall (or slug-function #'denote-sluggify-title)
str))
+ ((eq component 'keyword)
+ (replace-regexp-in-string
+ "_" ""
+ (funcall (or slug-function
#'denote-sluggify-keyword) str)))
+ ((eq component 'signature)
+ (funcall (or slug-function
#'denote-sluggify-signature) str)))))
+ (denote--replace-consecutive-token-characters str-slug)))
(make-obsolete
'denote-letter-case
- [elpa] externals/denote updated (99709c7a62 -> 76755e9a3c), ELPA Syncer, 2024/01/18
- [elpa] externals/denote d1ee270784 3/6: Add denote--replace-consecutive-token-characters and use it in denote-sluggify,
ELPA Syncer <=
- [elpa] externals/denote e715d68338 2/6: Add denote-link-description-function, ELPA Syncer, 2024/01/18
- [elpa] externals/denote 8d3900f8bf 1/6: Add denote--command-with-features and denote-save-buffer-after-creation, ELPA Syncer, 2024/01/18
- [elpa] externals/denote 76755e9a3c 6/6: Merge pull request #223 from jeanphilippegg/denote--replace-consecutive-token-characters, ELPA Syncer, 2024/01/18
- [elpa] externals/denote e83a377d08 4/6: Merge pull request #221 from jeanphilippegg/denote--command-with-features, ELPA Syncer, 2024/01/18
- [elpa] externals/denote fb1ed38229 5/6: Merge pull request #222 from jeanphilippegg/denote-link-description-function, ELPA Syncer, 2024/01/18