From 12e2d82a5a469aabadb1082678f7a33539779d8b Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Tue, 17 Jan 2023 23:49:05 +0100 Subject: compat-29: Add delete-line --- NEWS.org | 1 + compat-29.el | 28 ++++++++++++++++------------ compat-tests.el | 7 +++++++ compat.texi | 5 +++++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/NEWS.org b/NEWS.org index 31d5a52..a8ba33d 100644 --- a/NEWS.org +++ b/NEWS.org @@ -11,6 +11,7 @@ - compat-29: Add ~plist-get~ generalized variable. - compat-29: Add ~plistp~. - compat-29: Add ~list-of-strings-p~. +- compat-29: Add ~delete-line~. * Release of "Compat" Version 29.1.2.0 diff --git a/compat-29.el b/compat-29.el index e84c628..9373c0c 100644 --- a/compat-29.el +++ b/compat-29.el @@ -84,18 +84,6 @@ Unibyte strings are converted to multibyte for comparison." (declare (pure t) (side-effect-free t)) (eq t (compare-strings string1 0 nil string2 0 nil t))) -(compat-defun list-of-strings-p (object) ;; - "Return t if OBJECT is nil or a list of strings." - (declare (pure t) (side-effect-free t)) - (while (and (consp object) (stringp (car object))) - (setq object (cdr object))) - (null object)) - -(compat-defun plistp (object) ;; - "Non-nil if and only if OBJECT is a valid plist." - (let ((len (proper-list-p object))) - (and len (zerop (% len 2))))) - (compat-defun plist-get (plist prop &optional predicate) ;; "Handle optional argument PREDICATE." :explicit t @@ -183,6 +171,22 @@ This function does not move point. Also see `line-end-position'." ;;;; Defined in subr.el +(compat-defun list-of-strings-p (object) ;; + "Return t if OBJECT is nil or a list of strings." + (declare (pure t) (side-effect-free t)) + (while (and (consp object) (stringp (car object))) + (setq object (cdr object))) + (null object)) + +(compat-defun plistp (object) ;; + "Non-nil if and only if OBJECT is a valid plist." + (let ((len (proper-list-p object))) + (and len (zerop (% len 2))))) + +(compat-defun delete-line () ;; + "Delete the current line." + (delete-region (pos-bol) (pos-bol 2))) + (compat-defmacro with-memoization (place &rest code) ;; "Return the value of CODE and stash it in PLACE. If PLACE's value is non-nil, then don't bother evaluating CODE diff --git a/compat-tests.el b/compat-tests.el index a15f3f5..1b61570 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -906,6 +906,13 @@ (should (string-prefix-p "compat" (symbol-name (gensym "compat")))) (should-equal gensym-counter (+ orig 3)))) +(ert-deftest delete-line () + (with-temp-buffer + (insert "first\nsecond\nthird\n") + (goto-char 7) + (delete-line) + (should (equal (buffer-string) "first\nthird\n")))) + (ert-deftest list-of-strings-p () (should-not (list-of-strings-p 1)) (should (list-of-strings-p nil)) diff --git a/compat.texi b/compat.texi index 6aec7f4..bb86925 100644 --- a/compat.texi +++ b/compat.texi @@ -2013,6 +2013,11 @@ that there will be the need for changes, so use these functions with care. @c based on lisp/subr.el +@defun delete-line +Delete the current line. +@end defun + +@c based on lisp/subr.el @defun list-of-strings-p object Return @code{t} if @var{object} is @code{nil} or a list of strings. @end defun -- cgit v1.0