Save URL-encoded Text from Region to Kill Ring Buffer

しむどん 2024-11-03

While working with various tasks in Emacs, there arise occasions when processing a URL becomes necessary. In this case, I encountered the need to URL-encode some text, so I decided to write Emacs Lisp for this purpose.

;;; our-url.el --- URL Utility -*- lexical-binding: t; -*-
;; Copyright (C) 2024 TakesxiSximada
;;
;; Author: TakesxiSximada <[email protected]>
;; Maintainer: TakesxiSximada <[email protected]>
;; Keywords: URL
;; Version: 1
;; Date: 2024-11-03
;; Package-Version: 20241103.0000

;; This file is not part of GNU Emacs.

;;; License:

;; This program is free software: you can redistribute it and/or
;; modify it under the terms of the GNU Affero 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
;; Affero General Public License for more details.

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

;;; Commentary:

;; URL Tool.

;;; Code:


(require 'url-util)

(defun our-url-encode-region-to-kill-ring ()
  "URL encode the region string and add it to the circular buffer."
  (interactive)
  (kill-new
   (url-hexify-string
    (buffer-substring-no-properties
     (region-beginning) (region-end)))))

(provide 'our-url)

our-url.el