Skip to content

Latest commit

 

History

History
142 lines (106 loc) · 5.43 KB

README.org

File metadata and controls

142 lines (106 loc) · 5.43 KB

Smartrep http://melpa.org/packages/smartrep-badge.svg http://stable.melpa.org/packages/smartrep-badge.svg https://travis-ci.org/myuhe/smartrep.el.svg?branch=master https://coveralls.io/repos/myuhe/smartrep.el/badge.svg?branch=master

smartrep is a sequential command interface library. It enables the omittance of typing prefix keys. (e.g., C-c C-n C-n C-n … instead of C-c C-n C-c C-n C-c C-n …)

Contents

Usage

smartrep offers only one function smartrep-define-key. The key is bound with smartrep-define-key like:

(smartrep-define-key
    global-map "M-g"
  '(("n" . next-line)
    ("p" . previous-line)))

Then after typing M-g, n exetutes next-line and p executes previous-line.

If any other key is typed, the special key binding is canceled. That is, if n is typed, “n” is inserted as a character.

Examples

Control Two Buffers

Scroll another buffer. The current buffer is not changed. If you want to scroll by two lines in the other buffer, just type C-q n n.

(smartrep-define-key 
    global-map "C-q" '(("n" . (scroll-other-window 1))
                       ("p" . (scroll-other-window -1))
                       ("N" . 'scroll-other-window)
                       ("P" . (scroll-other-window '-))
                       ("a" . (beginning-of-buffer-other-window 0))
                       ("e" . (end-of-buffer-other-window 0))))

Change Window Size

Changing Window size tends to execute the same command continuously. It is boring work. So eval this example and type C-x { { {.

(smartrep-define-key
    global-map "C-x"
  '(("{" . shrink-window-horizontally)
    ("}" . enlarge-window-horizontally)))

Move header on Org-mode

Org-mode has complicated prefix keys. It is so frustrating.

This idea simplifies it. If you want to move from heading to heading, then type C-c and then C-n or C-p.

(smartrep-define-key 
    org-mode-map "C-c" '(("C-n" . (outline-next-visible-heading 1))
                         ("C-p" . (outline-previous-visible-heading 1))))

Remotely Control Firefox

You may control Firefox via Emacs.

This example enables the manipulation of Firefox to scroll up, down and more.

It requires moz.el

(autoload 'moz-minor-mode "moz" "Mozilla Minor and Inferior Mozilla Modes" t)
(moz-minor-mode t)

(defun moz-send-message (moz-command)
  (comint-send-string
   (inferior-moz-process)
   (concat moz-repl-name ".pushenv('printPrompt', 'inputMode'); "
           moz-repl-name ".setenv('inputMode', 'line'); "
           moz-repl-name ".setenv('printPrompt', false); undefined; "))
  (comint-send-string
   (inferior-moz-process)
   (concat moz-command
           moz-repl-name ".popenv('inputMode', 'printPrompt'); undefined;\n")))

(defun moz-scrolldown-1 ()
  (interactive)
   (moz-send-message "goDoCommand('cmd_scrollLineDown');\n")) 

(defun moz-scrolldown ()
  (interactive)
   (moz-send-message "goDoCommand('cmd_scrollPageDown');")) 

(defun moz-scrollup-1 ()
  (interactive)
   (moz-send-message "goDoCommand('cmd_scrollLineUp');\n")) 

(defun moz-scrollup ()
  (interactive)
   (moz-send-message "goDoCommand('cmd_scrollPageUp');")) 

(defun moz-top ()
  (interactive)
   (moz-send-message "goDoCommand('cmd_scrollTop');\n"))

(defun moz-bottom ()
  (interactive)
   (moz-send-message "goDoCommand('cmd_scrollBottom');\n"))

(require 'smartrep)

(smartrep-define-key 
 global-map "M-g" '(("n" . moz-scrolldown-1)
                    ("N" . moz-scrolldown)
                    ("p" . moz-scrollup-1)
                    ("P" . moz-scrollup)
                    ("a" . moz-top)
                    ("e" . moz-bottom)))

Smartrep Works In Many Applications

Many applications use smartrep. Thanks!!

Related article

Similar Applications

abo-abo/hydra