From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?I=C3=B1igo?= Serna Newsgroups: gmane.emacs.devel Subject: PROPOSAL: New function ffap-ip-at-point Date: Fri, 22 Jul 2022 10:49:30 +0200 Message-ID: <87r12d5xhv.fsf@gmx.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30142"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.8.6; emacs 29.0.50 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jul 22 11:23:38 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oEosk-0007ho-1b for ged-emacs-devel@m.gmane-mx.org; Fri, 22 Jul 2022 11:23:38 +0200 Original-Received: from localhost ([::1]:41554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oEosj-0000r9-1A for ged-emacs-devel@m.gmane-mx.org; Fri, 22 Jul 2022 05:23:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEobj-00088L-Bc for emacs-devel@gnu.org; Fri, 22 Jul 2022 05:06:04 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]:54727) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oEobf-0004oL-Rz for emacs-devel@gnu.org; Fri, 22 Jul 2022 05:06:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1658480749; bh=V21uCErQij+bkcxGhGDoFbq6Bl+xeM5ZsGGx9VOhFZM=; h=X-UI-Sender-Class:From:To:Subject:Date; b=I4uhcS3bEDF6n5W/b7i1clil20CBHRajfH6x6582gMSkYe9KYC+uZGu7e4lPPg/zY 5GyR7TPRd+UDiEAYPy1O/0FwEwWy4AA3D8wGbEg5+Tlgx/hWLW1BsTohZUx+9zOxnJ J20GqVOwzXqYEmdEBx+553qz26XuFSbl6xv+/tXQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from zeus.gmx.com ([79.154.9.68]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MRTRN-1nu93g2Szl-00NUJo; Fri, 22 Jul 2022 11:05:49 +0200 X-Provags-ID: V03:K1:zf8GrwDvLZeqTGSPiGM6fYHEwcz1Sr+27iZu/fntkZRWWkyiOtx bi1uPMqoQ+09gkos4uLa2zr+A8paK7CxwvMg5IDcwoaCuGH9Q7Fd1fOyqZTgbeOe20qi3Jn tzz6jQJ1LUuNiF+r1bXJPSIX6pJQOIpr1Gam8POFyOWpmTDfxQ5al+HxCfjvHdLGHpNy1m6 8YwAzHryg2EC/q5dDEpdA== X-UI-Out-Filterresults: notjunk:1;V03:K0:cvq0QiJsmiw=:7bHYyjK3JM5xsuEA3MMg3q fAPE9Yt5LvXvVnowKHK7yDN6WI+KWi4qdcgGqDSNNMr8snofTbX9FdR0njTAmRsNylPutqdhW WvTzK6rnjrAegmSBffmUoI7Z5Ik7PeZSEmfk9hhjuslVN8GKjOn68dEuCjxbY9HeqXzanKtgD iGny5KwZa57LDuHdpfn/FYilw/gbsQD89FowcPKMZ6tBNfIzhC0O2/1z5kOi7TKvfpd/8adbW W5uevhMbUDMmZHVs7SmJx45jHFn6LPLnhmCT2zupfOysoWq3qoRaVBowyQ6lICjhppk10lIeV xHYgQtoOGjvarySAhp+lj6Roe2X5yH9JBb+SWPCYJ12JEJEIksIDod90HgnyjPAHLN57rRcKH SvQhJF0hEAjLpslyopa683Jah2DngK0DfB9K3A2oUdFys32bb3WS8CemsGNdF9aIFP+sMU21L M8a3lxnynLia8tXSxdgpcNYXUw9c+/O8ctZ6WdKwFPSGWiR9RYCnP2GYs8fynTzGbqZBIBeYg q7STowDfqgyQS3dDDYT9J/RAvyYjpTARyW+sbqkeQtLjtv6snIvrVEPHhYjTNG/P4BoIn9gl7 zJQxgCGCjcOPA5YXBkTUnos6CUT3vCbmkzqO9fvEY9LgU4Elgwa5z4IxlZ97MacxheHDAXznH okm7Cnl5T7meva6bsG4aWy4mXaErr3zU2TCEIq7tK1qp+9mtpKcEKaoU95NS7J/pAnPFtxyuz qgyfq3uvQo+k5uWjAPP+1odUfh5Hy/jIT2xscXBQi/4yEpiRpQPShH7QQ2xom5QECWBAYBz7 Received-SPF: pass client-ip=212.227.17.22; envelope-from=inigoserna@gmx.com; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:292410 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Hi, I propose the addition of this `ffap-ip-at-point' function. Equivalent to (and based on) `ffap-machine-at-point', it will=20 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=20 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=20 it's everything ok. What do you think?=20 Btw, I signed FSF papers in 2021, so no problem here I guess. Thanks, --=20 I=C3=B1igo Serna --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=ffap-ip-at-point__dns-host-lookup.diff Content-Transfer-Encoding: quoted-printable diff --git a/lisp/ffap.el b/lisp/ffap.el index 9de0dd40d1..a0751fbd8e 100644 =2D-- 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))) +=0C +;;; 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 i= p start end) "\\.")))) + (message "|%S|%S|%S|" start end (length ip)) + (and (zerop start) + (length=3D ip end) + (seq-every-p #'(lambda (num) (and (>=3D num 0) (<=3D num 255))) = nums)))) + =0C ;;; 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 =2D-- 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 def= ault)) (if current-prefix-arg (read-from-minibuffer "Name server: ")))) (let ((options --=-=-=--