From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Nicolas Rybkin Newsgroups: gmane.emacs.devel Subject: [ELPA] New package: shorten-url Date: Fri, 1 Mar 2019 15:21:44 +0300 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000ef841905830773ea" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="131977"; mail-complaints-to="usenet@blaine.gmane.org" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Mar 01 14:37:14 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gziLh-000YAZ-0w for ged-emacs-devel@m.gmane.org; Fri, 01 Mar 2019 14:37:13 +0100 Original-Received: from localhost ([127.0.0.1]:37951 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gziLf-0006me-81 for ged-emacs-devel@m.gmane.org; Fri, 01 Mar 2019 08:37:11 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:46440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzhAx-00089v-1x for emacs-devel@gnu.org; Fri, 01 Mar 2019 07:22:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzhAu-0000dh-HN for emacs-devel@gnu.org; Fri, 01 Mar 2019 07:22:03 -0500 Original-Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:43517) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzhAt-0000cO-Nr for emacs-devel@gnu.org; Fri, 01 Mar 2019 07:22:00 -0500 Original-Received: by mail-lj1-x244.google.com with SMTP id z20so20184169ljj.10 for ; Fri, 01 Mar 2019 04:21:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=jC9PUIi1ebnT/7hkOCpz8sRNxFcowzS3seGrsFRiVFg=; b=Zw8gGIjzWrAQA2aJ9ai+evRQzktoAnPpcqWbeFfN4QarWO7a1O+0q4pf4Hipa158aG Thmb0HIrtRKNg5+J3uRQN64st0rAjbJ41ph6oOKitLJYFQnkqtljO6D4zZnWhVp1neB2 qlZ85lnoKSyHLV0pyqjgeYgV2zkCq17W88QW2/eqZfSVZMVCyeWWromMyqJ/zCcy6Ra1 wNFuUEVPNnIgqPqwqpPo70AdJSjaq3ZlyqmGL4WdOfqRYUdM7XIKblWuz7ATTFzo4tmz +wEvVic+dLUWzpCpm67MPHGQ7oOU59jtQjbR6CObPwSvmQUue5UfZMf4SazOVdvZ+K+O rs/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=jC9PUIi1ebnT/7hkOCpz8sRNxFcowzS3seGrsFRiVFg=; b=JJSrzuXbf5xFIs852dSiDnSYsnKBhudAylh/B8d7hzepzVB/m5/nhtHIUc7MlqgnBF F9RMEyVOFvjFW+gaqLoiK8ngSISv6Q2XE/EJF2at+8dUazSN97DoooUQomHO+MrseSoM HNdDLCW8xrt+7Sq77Brympxf2WFdnV8nH+lEO92fX9TfVcka2+9WybRh56Rul7EgnPu/ 98ZVpCFgucduw9iglwBudfjYs4KPcfPdh0p2HicsR7yd5m2G9UkEktZfZir1guZZPkGj vkpINfLrCiPdbsavDsJp8x/RKoIWQXrFs5sVjYORtlUx6GEt84geXoS7DetJjRHXKHCL ZoLA== X-Gm-Message-State: APjAAAUDFc79sjSvD2/gA/iN8T5RXTC9/v8xk32ddfWy/9wL1OstGHb8 zbROZ1LVSgrb4xO0+quPHTn1uKpPai//brvr0+LyaogJ X-Google-Smtp-Source: APXvYqyTQUh6dod0HdO5VK+bdR3cKE1a2NMpD08PdPHXitRHMwyRszHKSspJeMoau24IVJqbj/oUsxj47LcKIXgjYsM= X-Received: by 2002:a2e:9e09:: with SMTP id e9mr2545689ljk.14.1551442916638; Fri, 01 Mar 2019 04:21:56 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::244 X-Mailman-Approved-At: Fri, 01 Mar 2019 08:36:17 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:233723 Archived-At: --000000000000ef841905830773ea Content-Type: text/plain; charset="UTF-8" * SENT IT ON FEB 26 FROM ibmbull@yandex.ru, BUT GOT NO RESPNSE SO FAR. MAYBE YOUR SPAM FILTER FILTERS OUT ALL MAIL COMING FROM yandex.ru SERVER? * shorten-url allows you to insert a shortened alternative for a given URL. Can be useful for chatting. ;;; shorten-url.el --- URL shortener -*- lexical-binding: t; -*- ;; Copyright (C) 2019 Bad Blue Bull ;; Author: Bad Blue Bull > ;; Keywords: irc, icq ;; Version: 1.0 ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see ;; . ;;; Commentary: ;; shorten-url allows you to insert a shortened alternative for a given ;; URL. Can be useful for chatting. ;; ;; A request for a URL produced by concatenation of shorten-url-base ;; with a URL passed as an argument is fulfilled and data from HTTP ;; response gets inserted into current buffer. ;; ;; At the moment of this release TIMEOUT optional variable of ;; url-retrieve-synchronously may break execution of this function ;; (bug #34607), so it's unused. ;; ;; Also url-retrieve-synchronously takes long time to retrieve a URL ;; that hasn't been retrieved before in some interval of time in same ;; Emacs session (bug #34652). ;; Configuration: ;; You can customize shorten-url-base to use diffirent URL shortener web ;; service. ;; Usage: ;; Call shorten-url from Lisp or execute it as command with URL you want ;; to shorten passed as an argument. ;; ;; Example: ;; ;; M-x shorten-url https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34607 ;; ;; result inserted: https://qps.ru/MjrtW ;; ;; For convenient usage bind a key sequence so that it will insert ;; shortened version of URL stored in kill ring. ;; Here is example how you can bind C-c C-y key sequence so that when it ;; is used in ERC it inserts a shortened URL corresponding to element of ;; kill ring that the yank command would insert: ;; ;; (add-hook 'erc-mode-hook (lambda () ;; (local-set-key (kbd "C-c C-y") ;; (lambda (&optional arg) ;; (interactive "*P") ;; (shorten-url (current-kill ;; (cond ;; ((listp arg) ;; 0) ;; ((eq arg '-) ;; -2) ;; (t ;; (1- arg))) ;; )))))) ;;; Code: (provide 'shorten-url) (defcustom shorten-url-base "https://qps.ru/api?url=" "base for URL shortener. short-url will concatenate it with URL passed as argument" :type '(choice (const :tag "https://qps.ru/api?url=" "https://qps.ru/api?url=") (const :tag "https://clck.ru/--?url=" "https://clck.ru/--?url=") (string :tag "custom" ""))) (defun shorten-url (url) "Insert shortened URL (passed as argument). Contact a URL produced by concatenation shorten-url-base and the argument and insert data from response from the server into current buffer." (interactive "sURL to shorten: ") (insert (with-current-buffer (url-retrieve-synchronously (concat shorten-url-base url) nil 't) (goto-char (point-min)) (search-forward "\n\n" nil 't) (unwind-protect (buffer-substring (point) (point-max)) (kill-buffer (current-buffer))))) (message "inserted shortened URL for %s" url)) ;;; shorten-url.el ends here --000000000000ef841905830773ea Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
* SENT IT ON FEB 26 FROM ibmbull@yandex.ru, BUT GOT NO RESPNSE SO FAR.=C2=A0 MAYB= E YOUR SPAM FILTER FILTERS OUT ALL MAIL COMING FROM yandex.ru SERVER? *

shorten-url allows y= ou to insert a shortened alternative for a given URL.=C2=A0 Can be useful f= or chatting.
=C2=A0
;;; shorten-url.el --- URL shortene= r=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 -*- lexical-binding: t; -= *-

;; Copyright (C) 2019 Bad Blue Bull

;; Author: Bad Blue Bu= ll <ibmbull@yandex.ru>
;; Keywords: irc, icq

;; Version: 1.0<= br>
;; This program is free software; you can redistribute it and/or mod= ify
;; it under the terms of the GNU General Public License as published= by
;; the Free Software Foundation, either version 3 of the License, or= (at
;; your option) any later version.

;; This program is distri= buted in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; w= ithout even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A = PARTICULAR PURPOSE.=C2=A0 See the GNU
;; General Public License for more= details.

;; You should have received a copy of the GNU General Publ= ic License
;; along with this program.=C2=A0 If not, see
;; <https://www.gnu.org/licenses/= >.

;;; Commentary:

;; shorten-url allows you to insert a s= hortened alternative for a given
;; URL.=C2=A0 Can be useful for chattin= g.
;;
;; A request for a URL produced by concatenation of shorten-url= -base
;; with a URL passed as an argument is fulfilled and data from HTT= P
;; response gets inserted into current buffer.
;;
;; At the mome= nt of this release TIMEOUT optional variable of
;; url-retrieve-synchron= ously may break execution of this function
;; (bug=C2=A0 #34607), so it&= #39;s unused.
;;
;; Also url-retrieve-synchronously takes long time t= o retrieve a URL
;; that hasn't been retrieved before in some interv= al of time in same
;; Emacs session (bug #34652).

;; Configuratio= n:

;; You can customize shorten-url-base to use diffirent URL shorte= ner web
;; service.

;; Usage:

;; Call shorten-url from Lis= p or execute it as command with URL you want
;; to shorten passed as an = argument.
;;
;; Example:
;;
;; M-x shorten-url https://debbugs.gnu.= org/cgi/bugreport.cgi?bug=3D34607
;;
;; result inserted: https://qps.ru/MjrtW
;;
;; For con= venient usage bind a key sequence so that it will insert
;; shortened ve= rsion of URL stored in kill ring.
;; Here is example how you can bind C-= c C-y key sequence so that when it
;; is used in ERC it inserts a shorte= ned URL corresponding to element of
;; kill ring that the yank command w= ould insert:
;;
;; (add-hook 'erc-mode-hook (lambda ()
;; =C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 (local-s= et-key (kbd "C-c C-y")
;; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0 (lambda = (&optional arg)
;; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 (interac= tive "*P")
;; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 (shorten= -url (current-kill
;; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0 (cond
;; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0= =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 ((listp arg)
;; =C2=A0=C2=A0 =C2=A0=C2=A0= =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 0)
;; =C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 ((eq arg '= -)
;; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0= =C2=A0=C2=A0 -2)
;; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 = =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 (t
;; =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0= =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 (1- arg)))
;; =C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0= =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0 ))))))

;;; Code:
(provide 'shorten-url)

(defcustom shorten-url-base "https://qps.ru/api?url=3D"=C2=A0 "base for URL shortener.
short-url will concatenate it with= URL passed as argument"
=C2=A0 :type '(choice (const :tag &quo= t;https://qps.ru/api?url=3D&= quot;
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0"https://qps.ru/api?url=3D"= )
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 (const :tag "https://clck.ru/--?url=3D"
=C2=A0= =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0"https://clck.ru/--?url=3D")
=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0 (string :tag "custom" "")= ))

(defun shorten-url (url)
=C2=A0 "Insert shortened URL (pa= ssed as argument).
Contact a URL produced by concatenation shorten-url-b= ase and the
argument and insert data from response from the server into = current
buffer."
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (interacti= ve "sURL to shorten: ")
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (= insert (with-current-buffer
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0= =C2=A0 (url-retrieve-synchronously
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0=C2=A0 (concat shorten-url-base url) nil 't)
=C2=A0= =C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 (goto-char (point-min))
=C2=A0=C2=A0 = =C2=A0=C2=A0=C2=A0 =C2=A0 (search-forward "\n\n" nil 't)
= =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 (unwind-protect
=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (buffer-substring (point) (p= oint-max))
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 (kill-buff= er (current-buffer)))))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (message &q= uot;inserted shortened URL for %s" url))

;;; shorten-url.el end= s here

=C2=A0
--000000000000ef841905830773ea--