リージョンのテキストをURLエンコードしてkill-ringバッファに保存する

しむどん 2024-11-03

Emacsで様々な作業をしているとURLを加工する必要がでてくる事がある。今回は、URLをURLエンコードして、その文字列を使うという機会に出会った。そこで、そのためのEmacs Lispを書く事にした。

;;; 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