help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tmux replacement or integration with Emacs.


From: Emanuel Berg
Subject: Re: Tmux replacement or integration with Emacs.
Date: Wed, 03 Feb 2021 08:32:46 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jean Louis wrote:

> (set-register ?e #s(kmacro-register [134217848 ?e ?s ?h ?e ?l ?l return]))
>
> Then I invoke it with {C-x r j e} to get to eshell.

So that's the way one is supposed to do it. I wrote this, it
works just the same way [last]

> Yes, that is all complicated and not user friendly. It is
> however in my muscle memory and that is how I get faster to
> some buffers.

It gets SOO much faster!

;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;;   http://user.it.uu.se/~embe8573/emacs-init/navigate-fs-keys.el
;;;   https://dataswamp.org/~incal/emacs-init/navigate-fs-keys.el

(require 'cl-lib)
(require 'count)
(require 'files-my)
(require 'netrc)
(require 'nnmail)
(require 'sudo-user-path)
(require 'super)
(require 'w3m-bookmark)

(defun do-show-file (file)
  (interactive "ffile: ")
  (let ((this-buffer   (current-buffer))
        (target-buffer (find-file-noselect file) ))
    (if (eq this-buffer target-buffer)
        (message "already here")
      (find-file file)
      (unless (buffer-modified-p)
        (revert-buffer t t nil)) )))

(defun shortcut-to-file (key-prefix key file &optional file-prefix)
  "Make shortcut with key KEY-PREFIX KEY to FILE-PREFIX FILE."
  (let*((key (format "%s%s" key-prefix key))
                (file-dir (or file-prefix "~"))
                (file     (expand-file-name file file-dir)))
    (global-set-key key
                    (lambda () (interactive) (do-show-file file)) )))

(define-prefix-command        'C-j-prefix-name)
(super-global-set-key  "\C-j" 'C-j-prefix-name)

(defun shortcut-to-function (key-prefix key function)
  (global-set-key (format "%s%s" key-prefix key) function) )

(defun set-keys (ks &optional key path)
  (let ((key      (format "%s%s" (or key  "") (car  ks)))
        (the-path (format "%s%s" (or path "") (cadr ks)))
        (kps (cl-caddr ks)))
    (dolist (kp kps)
      (if (= 2 (length kp))
          (if (functionp (cadr kp))
              (shortcut-to-function key (car kp) (cadr kp))
            (shortcut-to-file key (car kp) (cadr kp) the-path) )
        (set-keys kp key the-path) ))))

(set-keys
 `("\C-j" ; invoke key
   "~/"   ; base path
   (
    ;; SYNTAX: ("key" "absolute path") - OK
    ;;         ("key" "relative path") - OK
    ;;         ("key" function)        - interactive lambda only
    ;;         ("key" ,variable)       - first `require'
    ;;
    ;;  NOTES: * keys are case sensitive but A is a when A is
    ;;           unset
    ;;         * path syntax works: e.g., ~ and /sudo:user@host:/path
    ;;           (for sudo, see `sudo-user-path')
    ;;         * can be nested - hint: make it mnemonic
    ;;           especially for non-everyday shortcuts. e.g.,
    ;;           C-j e w k -> (e)macs (w)3m (k)eys
    ;;                     -> ~/.emacs.d/emacs-init/w3m/w3m-keys.el
    ("." (lambda () (interactive) (dired-jump)))
    ("A" ,(sudo-root-path "/etc/apt/sources.list"))
    ("a" "public_html/GEAR")
    ("b" "public_html/books/" (
                               ("." ".")
                               ("b" "books.bib")
                               ("l" "books.tex")
                               ("m" "Makefile")
                               ))
    ;; etc
    )))

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]