From: Nicolas Rybkin <nr68020@gmail.com>
To: emacs-devel@gnu.org
Subject: [ELPA] New package: shorten-url
Date: Fri, 1 Mar 2019 15:21:44 +0300 [thread overview]
Message-ID: <CAJAcu-VR5H6chQSu=f=RcJYdsauVJR9kHF2tKsPrcYv59bB7+A@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 4071 bytes --]
* 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 <ibmbull@yandex.ru <bad_blue_bull@yandex.ru>>
;; 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
;; <https://www.gnu.org/licenses/>.
;;; 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
[-- Attachment #2: Type: text/html, Size: 6235 bytes --]
next reply other threads:[~2019-03-01 12:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-01 12:21 Nicolas Rybkin [this message]
2019-03-02 3:30 ` [ELPA] New package: shorten-url Amin Bandali
2019-03-02 3:34 ` Richard Stallman
2019-03-02 11:52 ` Nicolas Rybkin
2019-03-03 3:00 ` Richard Stallman
2019-03-03 14:36 ` Nicolas Rybkin
2019-03-04 3:27 ` Richard Stallman
2019-03-04 6:52 ` Nicolas Rybkin
2019-03-02 13:37 ` Yuri Khan
2019-03-02 16:05 ` Nicolas Rybkin
2019-03-02 17:37 ` Yuri Khan
2019-03-03 2:46 ` Van L
-- strict thread matches above, loose matches on Subject: below --
2019-02-25 21:15 Bad Blue Bull
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJAcu-VR5H6chQSu=f=RcJYdsauVJR9kHF2tKsPrcYv59bB7+A@mail.gmail.com' \
--to=nr68020@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).