diff --git a/config-min.org b/config-min.org index 4146ada..5384e6d 100644 --- a/config-min.org +++ b/config-min.org @@ -274,8 +274,8 @@ (global-set-key (kbd "M-F") 'forward-word) ;; Goto-char - (use-package iy-go-to-char - :bind (("M-m" . #'iy-go-to-char))) + (require 'brumlow-goto-char) + (global-set-key (kbd "M-m") #'jump-to-char) #+end_src * window manipulation #+begin_src emacs-lisp diff --git a/lisp/brumlow-goto-char.el b/lisp/brumlow-goto-char.el new file mode 100644 index 0000000..e38ba59 --- /dev/null +++ b/lisp/brumlow-goto-char.el @@ -0,0 +1,68 @@ +;;; brumlow-goto-char.el --- -*- lexical-binding: t -*- + +;; Copyright (C) 2020 Benson Chu + +;; Author: Benson Chu +;; Created: [2020-12-30 14:11] + +;; This file is not part of GNU Emacs + +;; 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: + +;;; Code: +(defvar jump-to-last-char nil) +(defvar jump-to-last-count nil) + +(defun jump-to-char-repate-forward () + "Repate the last jump-to-char forward" + (interactive) + (forward-char) + (jump-to-char-fun jump-to-last-char (abs jump-to-last-count))) + +(defun jump-to-char-repate-backwards () + "Repate the last jump-to-char backward" + (interactive) + (jump-to-char-fun jump-to-last-char (- (abs jump-to-last-count)))) + +(defun jump-to-char-fun (char count) + "Jump to char function" + (if (search-forward (string char) nil t count) + (when (> count 0) + (backward-char)) + (message "Search Failed: %s" (char-to-string char))) + (setq jump-to-last-char char) + (setq jump-to-last-count count) + (unless defining-kbd-macro + (set-temporary-overlay-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd ";") 'jump-to-char-repate-forward) + (define-key map (kbd ",") 'jump-to-char-repate-backwards) + map)))) + +(defun jump-to-char (arg) + "Jump to char" + (interactive "p") + (message nil) + (let ((char (read-char "jump-to-char: "))) + (jump-to-char-fun char arg))) + +(defun jump-to-char-backward (arg) + "Jump to char backwards" + (interactive "p") + (jump-to-char (- arg))) + +(provide 'brumlow-goto-char) +;;; brumlow-goto-char.el ends here