emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 203279a 1/4: Add new function image-at-point-p


From: Stefan Kangas
Subject: master 203279a 1/4: Add new function image-at-point-p
Date: Tue, 26 Oct 2021 22:38:58 -0400 (EDT)

branch: master
commit 203279a02448c6d9cfc766ae5dd159cdacabd7df
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    Add new function image-at-point-p
    
    * lisp/image.el (image-at-point-p): New defun.
    * doc/lispref/display.texi (Showing Images): Document above new defun.
---
 doc/lispref/display.texi | 5 +++++
 etc/NEWS                 | 5 +++++
 lisp/image.el            | 7 +++++++
 3 files changed, 17 insertions(+)

diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index cc9ca28..92932af 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -6549,6 +6549,11 @@ cache, it can always be displayed, even if the value of
 @code{max-image-size} is subsequently changed (@pxref{Image Cache}).
 @end defvar
 
+@defun image-at-point-p
+This function returns @code{t} if point is on an image, and @code{nil}
+otherwise.
+@end defun
+
 Images inserted with the insertion functions above also get a local
 keymap installed in the text properties (or overlays) that span the
 displayed image.  This keymap defines the following commands:
diff --git a/etc/NEWS b/etc/NEWS
index 6d32569..1cb19ee 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -386,6 +386,11 @@ something usable even if the syntax of the argument isn't 
completely
 correct.  The 'kbd-valid-p' predicate does a stricter check of the
 syntax.
 
++++
+** New function 'image-at-point-p'.
+This function returns t if point is on a valid image, and nil
+otherwise.
+
 
 * Changes in Emacs 29.1 on Non-Free Operating Systems
 
diff --git a/lisp/image.el b/lisp/image.el
index 5343e26..bfcbb66 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -1140,6 +1140,13 @@ default is 20%."
       (error "No image under point"))
     image))
 
+;;;###autoload
+(defun image-at-point-p ()
+  "Return non-nil if there is an image at point."
+  (condition-case nil
+      (prog1 t (image--get-image))
+    (error nil)))
+
 (defun image--get-imagemagick-and-warn (&optional position)
   (declare-function image-transforms-p "image.c" (&optional frame))
   (unless (or (fboundp 'imagemagick-types) (image-transforms-p))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]