all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* PROPOSAL: New function ffap-ip-at-point
@ 2022-07-22  8:49 Iñigo Serna
  2022-07-22  9:36 ` Robert Pluim
  2022-07-22 11:20 ` Eli Zaretskii
  0 siblings, 2 replies; 19+ messages in thread
From: Iñigo Serna @ 2022-07-22  8:49 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 591 bytes --]

Hi,

I propose the addition of this `ffap-ip-at-point' function.
Equivalent to (and based on) `ffap-machine-at-point', it will 
return
the IP address at point if it exists, or nil.

The attached patch also includes a very minor change to
`dns-lookup-host' command in order to use it if 
ffap-machine-at-point
first fails.

Patch is against master from a couple of hours ago.
This is my first serious contribution to emacs, so I'm not sure 
it's everything ok.
What do you think? 

Btw, I signed FSF papers in 2021, so no problem here I guess.

Thanks,
-- 
Iñigo Serna

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ffap-ip-at-point__dns-host-lookup.diff --]
[-- Type: text/x-patch, Size: 1929 bytes --]

diff --git a/lisp/ffap.el b/lisp/ffap.el
index 9de0dd40d1..a0751fbd8e 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -641,6 +641,25 @@ ffap-fixup-url
    ((and ffap-url-unwrap-remote (ffap-url-unwrap-remote url)))
    (url)))

+\f
+;;; IP Address (`ffap-ip-p'):
+
+;;;###autoload
+(defun ffap-ip-at-point ()
+  "Return IP address at point if it exists, or nil."
+  (let ((mach (ffap-string-at-point 'ip)))
+    (and (ffap-ip-p mach) mach)))
+
+(defun ffap-ip-p (ip)
+  "Decide whether IP is a valid IP address."
+  (when-let* ((start (string-match "\\([0-9]\\{1,3\\}\\.\\)\\{3\\}[0-9]\\{1,3\\}" ip))
+              (end (match-end 0))
+              (nums (mapcar #'string-to-number (split-string (substring ip start end) "\\."))))
+    (message "|%S|%S|%S|" start end (length ip))
+    (and (zerop start)
+         (length= ip end)
+         (seq-every-p #'(lambda (num) (and (>= num 0) (<= num 255))) nums))))
+
 \f
 ;;; File Name Handling:
 ;;
@@ -1094,6 +1113,8 @@ ffap-string-at-point-mode-alist
     (nocolon "--9$+<>@-Z_[:alpha:]~" "<@" "@>;.,!?")
     ;; A machine:
     (machine "-[:alnum:]." "" ".")
+    ;; An IP address:
+    (ip "[0-9]." "" ".")
     ;; Mathematica paths: allow backquotes
     (math-mode ",-:$+<>@-Z_[:lower:]~`" "<" "@>;.,!?`:")
     ;; (La)TeX: don't allow braces
diff --git a/lisp/net/net-utils.el b/lisp/net/net-utils.el
index c7ff175e08..4bcfcb122d 100644
--- a/lisp/net/net-utils.el
+++ b/lisp/net/net-utils.el
@@ -577,7 +577,7 @@ dns-lookup-host

 This command uses `dns-lookup-program' for looking up the DNS information."
   (interactive
-   (list (let ((default (ffap-machine-at-point)))
+   (list (let ((default (or (ffap-machine-at-point) (ffap-ip-at-point))))
            (read-string (format-prompt "Lookup host" default) nil nil default))
          (if current-prefix-arg (read-from-minibuffer "Name server: "))))
   (let ((options

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-07-26 12:54 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-22  8:49 PROPOSAL: New function ffap-ip-at-point Iñigo Serna
2022-07-22  9:36 ` Robert Pluim
2022-07-22 11:20 ` Eli Zaretskii
2022-07-22 14:46   ` Iñigo Serna
2022-07-22 15:01     ` Eli Zaretskii
2022-07-22 15:04     ` Brian Cully via Emacs development discussions.
2022-07-22 15:28       ` Iñigo Serna
2022-07-22 15:09     ` Lars Ingebrigtsen
2022-07-22 15:34       ` Iñigo Serna
2022-07-22 15:55         ` Robert Pluim
2022-07-22 20:10         ` Lars Ingebrigtsen
2022-07-23  7:31           ` Robert Pluim
2022-07-23  7:37             ` Lars Ingebrigtsen
2022-07-23  7:46               ` Robert Pluim
2022-07-23  7:47                 ` Lars Ingebrigtsen
2022-07-26 12:21                   ` Robert Pluim
2022-07-26 12:48                     ` Eli Zaretskii
2022-07-26 12:54                       ` Robert Pluim
2022-07-23  7:39             ` Andreas Schwab

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.