From 203279a02448c6d9cfc766ae5dd159cdacabd7df Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Wed, 27 Oct 2021 03:22:09 +0200 Subject: [PATCH] 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 cc9ca28bf02..92932af9ba1 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 6d3256959ea..1cb19ee888c 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 5343e26d032..bfcbb66c251 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)) -- 2.39.2