[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 01ea1c2cc4 12/17: Remove unnecessary checks
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/denote 01ea1c2cc4 12/17: Remove unnecessary checks |
|
Date: |
Thu, 23 Nov 2023 00:58:04 -0500 (EST) |
branch: externals/denote
commit 01ea1c2cc46bd07928a354dab1f8c3349c187d41
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Remove unnecessary checks
---
denote.el | 89 ++++++++++++++++++++++++++++-----------------------------------
1 file changed, 39 insertions(+), 50 deletions(-)
diff --git a/denote.el b/denote.el
index 5387c8f527..460ad61370 100644
--- a/denote.el
+++ b/denote.el
@@ -598,8 +598,7 @@ things accordingly.")
(defun denote--make-denote-directory ()
"Make the variable `denote-directory' and its parents, if needed."
- (when (and (stringp denote-directory)
- (not (file-directory-p denote-directory)))
+ (when (not (file-directory-p denote-directory))
(make-directory denote-directory :parents)))
(defvar denote-user-enforced-denote-directory nil
@@ -691,9 +690,7 @@ Perform letter casing according to
`denote-file-name-letter-casing'."
(defun denote-sluggify-keywords (keywords)
"Sluggify KEYWORDS, which is a list of strings."
- (if (listp keywords)
- (mapcar #'denote-sluggify-and-join keywords)
- (error "`%s' is not a list" keywords)))
+ (mapcar #'denote-sluggify-and-join keywords))
;; TODO 2023-05-22: Review name of `denote-desluggify' to signify what
;; the doc string warns about.
@@ -739,15 +736,13 @@ For our purposes, a note must not be a directory, must
satisfy
(defun denote-file-has-identifier-p (file)
"Return non-nil if FILE has a Denote identifier."
- (when file
- (string-match-p (concat "\\`" denote-id-regexp)
- (file-name-nondirectory file))))
+ (string-match-p (concat "\\`" denote-id-regexp)
+ (file-name-nondirectory file)))
(defun denote-file-has-signature-p (file)
"Return non-nil if FILE has a Denote identifier."
- (when file
- (string-match-p denote-signature-regexp
- (file-name-nondirectory file))))
+ (string-match-p denote-signature-regexp
+ (file-name-nondirectory file)))
(make-obsolete 'denote-file-directory-p nil "2.0.0")
@@ -919,7 +914,7 @@ The path is relative to DIRECTORY (default:
‘default-directory’)."
With optional OMIT-CURRENT, do not include the current Denote
file in the returned list."
(let ((files (denote-directory-files)))
- (if (and omit-current (denote-file-has-identifier-p buffer-file-name))
+ (if (and omit-current buffer-file-name (denote-file-has-identifier-p
buffer-file-name))
(delete buffer-file-name files)
files)))
@@ -1395,21 +1390,20 @@ Run `denote-desluggify' on title if the extraction is
sucessful."
(defun denote--file-with-temp-buffer-subr (file)
"Return path to FILE or its buffer together with the appropriate function.
Subroutine of `denote--file-with-temp-buffer'."
- (when file
- (let* ((buffer (get-file-buffer file))
- (file-exists (file-exists-p file))
- (buffer-modified (buffer-modified-p buffer)))
- (cond
- ((or (and file-exists
- buffer
- (not buffer-modified)
- (not (eq buffer-modified 'autosaved)))
- (and file-exists (not buffer)))
- (cons #'insert-file-contents file))
- (buffer
- (cons #'insert-buffer buffer))
- (t
- (error "Cannot find anything about file `%s'" file))))))
+ (let* ((buffer (get-file-buffer file))
+ (file-exists (file-exists-p file))
+ (buffer-modified (buffer-modified-p buffer)))
+ (cond
+ ((or (and file-exists
+ buffer
+ (not buffer-modified)
+ (not (eq buffer-modified 'autosaved)))
+ (and file-exists (not buffer)))
+ (cons #'insert-file-contents file))
+ (buffer
+ (cons #'insert-buffer buffer))
+ (t
+ (error "Cannot find anything about file `%s'" file)))))
(defmacro denote--file-with-temp-buffer (file &rest body)
"If FILE exists, insert its contents in a temp buffer and call BODY."
@@ -1554,7 +1548,7 @@ path to DIR."
"Expand DATE in an appropriate format for FILE-TYPE."
(let ((format denote-date-format))
(cond
- ((stringp format)
+ (format
(format-time-string format date))
((when-let ((fn (denote--date-format-function file-type)))
(funcall fn date)))
@@ -1586,10 +1580,6 @@ TEMPLATE, and SIGNATURE should be valid for note
creation."
"Return a valid filetype given the argument FILETYPE.
If none is found, the first element of `denote-file-types' is
returned."
- (unless (or (symbolp filetype) (stringp filetype))
- (user-error "`%s' is not a symbol or string" filetype))
- (when (stringp filetype)
- (setq filetype (intern filetype)))
(if (memq filetype (mapcar 'car denote-file-types))
filetype
(caar denote-file-types)))
@@ -3024,14 +3014,13 @@ treats the active region specially, is up to it."
current-prefix-arg)))
(let* ((beg (point))
(identifier-only (or id-only (string-empty-p description))))
- (when file
- (insert
- (denote-format-link
- file
- (denote-link--file-type-format file-type identifier-only)
- description))
- (unless (derived-mode-p 'org-mode)
- (make-button beg (point) 'type 'denote-link-button)))))
+ (insert
+ (denote-format-link
+ file
+ (denote-link--file-type-format file-type identifier-only)
+ description))
+ (unless (derived-mode-p 'org-mode)
+ (make-button beg (point) 'type 'denote-link-button))))
(define-obsolete-function-alias
'denote-link-insert-link
@@ -3318,7 +3307,8 @@ When called from Lisp, with optional BEG and END as buffer
positions, limit the process to the region in-between."
(interactive)
(when (and (not (derived-mode-p 'org-mode))
- (denote-file-has-identifier-p (buffer-file-name)))
+ buffer-file-name
+ (denote-file-has-identifier-p buffer-file-name))
(save-excursion
(goto-char (or beg (point-min)))
(while (re-search-forward denote-id-regexp end t)
@@ -3727,14 +3717,14 @@ With optional PATH-ID return a cons cell consisting of
the path
and the identifier."
(let* ((search (and (string-match "::\\(.*\\)\\'" link)
(match-string 1 link)))
- (id (if (and (stringp search) (not (string-empty-p search)))
+ (id (if (and search (not (string-empty-p search)))
(substring link 0 (match-beginning 0))
link))
(path (denote-get-path-by-id id)))
(cond
(path-id
(cons (format "%s" path) (format "%s" id)))
- ((and (stringp search) (not (string-empty-p search)))
+ ((and search (not (string-empty-p search)))
(concat path "::" search))
(path))))
@@ -4147,13 +4137,12 @@ and errors and if the word at point is not a Denote
identifier."
(cl-defmethod xref-backend-definitions ((_backend (eql 'denote)) identifier)
"Return xref for the note IDENTIFIER points to."
- (let ((file (denote-get-path-by-id identifier)))
- (when file
- (if (file-equal-p file (buffer-file-name (current-buffer)))
- (user-error "Identifier points to the current buffer")
- ;; Without the message, Xref will report that the ID does not
- ;; exist, which is incorrect in this case.
- (list (xref-make nil (xref-make-file-location file 0 0)))))))
+ (when-let ((file (denote-get-path-by-id identifier)))
+ (if (file-equal-p file (buffer-file-name (current-buffer)))
+ (user-error "Identifier points to the current buffer")
+ ;; Without the message, Xref will report that the ID does not
+ ;; exist, which is incorrect in this case.
+ (list (xref-make nil (xref-make-file-location file 0 0))))))
(cl-defmethod xref-backend-references ((_backend (eql 'denote)) identifier)
"Return list of xrefs where IDENTIFIER is referenced.
- [elpa] externals/denote cf63fd9015 05/17: Simplify denote-keywords-add and denote-keywords-remove, (continued)
- [elpa] externals/denote cf63fd9015 05/17: Simplify denote-keywords-add and denote-keywords-remove, ELPA Syncer, 2023/11/23
- [elpa] externals/denote b936bbdf4e 08/17: Make signature parameter non optional for some functions, ELPA Syncer, 2023/11/23
- [elpa] externals/denote 70d07dd122 02/17: Fix typo, ELPA Syncer, 2023/11/23
- [elpa] externals/denote 9742bca7e3 09/17: Fix denote-change-file-type-and-front-matter when there is a signature, ELPA Syncer, 2023/11/23
- [elpa] externals/denote ba7561688d 01/17: Remove unnecessary code in denote-trim-* functions and denote-extract-keywords-from-front-matter, ELPA Syncer, 2023/11/23
- [elpa] externals/denote 8e4a8ee69b 15/17: Refactor denote--link-in-context-regexp, ELPA Syncer, 2023/11/23
- [elpa] externals/denote b5d3ab6e4e 17/17: Merge pull request #193 from jeanphilippegg/cleanups, ELPA Syncer, 2023/11/23
- [elpa] externals/denote 39847ad78b 16/17: Refactor denote--link-format, ELPA Syncer, 2023/11/23
- [elpa] externals/denote 53d52d9d46 07/17: Fix documentation of denote-file-type, ELPA Syncer, 2023/11/23
- [elpa] externals/denote b5810569fe 10/17: Refactor denote--find-first-unused-id, ELPA Syncer, 2023/11/23
- [elpa] externals/denote 01ea1c2cc4 12/17: Remove unnecessary checks,
ELPA Syncer <=
- [elpa] externals/denote 3ebc7026d4 11/17: signature should always be a string (maybe empty), ELPA Syncer, 2023/11/23
- [elpa] externals/denote 2d6131085c 06/17: Simplify denote-filetype-heuristics, ELPA Syncer, 2023/11/23
- [elpa] externals/denote 8255dc380f 14/17: Simplify denote-trim-whitespace, ELPA Syncer, 2023/11/23
- [elpa] externals/denote 1b24d2ed5a 04/17: Simplify denote-format-file-name, ELPA Syncer, 2023/11/23