Coder Social home page Coder Social logo

alamode's Introduction

#!/usr/bin/env mdsh

alamode

;;; alamode.el --- a simple package                     -*- lexical-binding: t; -*-

;; Copyright (C) 2021  Jeet Ray

;; Author: Jeet Ray <[email protected]>
;; Keywords: lisp
;; Version: 0.0.1

;; 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 <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Put a description of the package here

;;; Code:

(require 'dash)
(require 'meq)
(require 'deino)
(require 'prime)
(require 'uru)

(defvar meq/var/all-keymaps-map nil)
(defvar meq/var/alamode-aiern-was-on (member "aiern" meq/var/ignored-modal-prefixes))
(defvar meq/var/alamode-evil-was-on (member "evil" meq/var/ignored-modal-prefixes))

;; Adapted From: https://gitlab.com/jjzmajic/cosmoem.el/-/blob/master/cosmoem.el#L83
;;;###autoload
(defun meq/toggle-inner (mode prefix mode-on map &optional use-cosmoem force) (interactive)
    (meq/disable-all-modal-modes nil (not mode-on))
    (if mode-on
        (when force (meq/which-key--show-popup map force))
        (funcall mode 1)
        (with-eval-after-load 'which-key
            (if use-cosmoem (ignore-errors (funcall (meq/inconcat "meq/" prefix "-cosmoem-show")))
                (meq/which-key-show-top-level map)))))

;; Adapted From: https://github.com/emacsorphanage/god-mode/blob/master/god-mode.el#L392
;;;###autoload
(defun meq/execute-with-current-bindings-inner (mode prefix mode-on map &optional use-cosmoem called-interactively)
    (interactive "d")
    (unless mode-on
        (letrec ((caller this-command)
                (buffer (current-buffer))
                (cleanup
                    (lambda ()
                    ;; Perform cleanup in original buffer even if the command
                    ;; switched buffers.
                    (if (buffer-live-p buffer)
                        (with-current-buffer buffer
                            (unwind-protect
                                (progn
                                    (setq overriding-terminal-local-map meq/var/alamode-backup-terminal-local-map)
                                    (funcall mode -1)
                                    (when meq/var/alamode-aiern-was-on (aiern-mode 1))
                                    (when meq/var/alamode-evil-was-on (evil-mode 1))
                                    (meq/which-key-show-top-level))
                                (remove-hook 'post-command-hook post-hook)))
                        (remove-hook 'post-command-hook post-hook))))
                (kill-transient-map (lambda nil (interactive)
                                        (set-transient-map map 'meq/god-prefix-command-p cleanup)))
                (post-hook (lambda nil (unless (and
                                                (eq this-command caller)
                                                ;; If we've entered the minibuffer, this implies
                                                ;; a non-prefix command was run, even if
                                                ;; `this-command' has not changed.  For example,
                                                ;; `execute-extended-command' behaves this way.
                                                (not (window-minibuffer-p)))
                                            (funcall kill-transient-map)))))
            (add-hook 'post-command-hook post-hook)
            ;; Pass the current prefix argument along to the next command.
            (setq prefix-arg current-prefix-arg)
            ;; Technically we don't need to activate %p mode since the
            ;; transient keymap is already in place, but it's useful to provide
            ;; a mode line lighter and run any hook functions the user has set
            ;; up.  This could be made configurable in the future.
            (funcall mode 1)
            (with-eval-after-load 'which-key (meq/which-key-show-top-level map))
            (setq meq/var/alamode-backup-terminal-local-map overriding-terminal-local-map)
            (setq deino-enabled-temporarily t
                overriding-terminal-local-map (symbol-value map))
            (when (string= prefix "god")
                (when (meq/fbatp aiern-mode) (setq meq/var/alamode-aiern-was-on t) (aiern-mode -1))
                (when (meq/fbatp evil-mode) (setq meq/var/alamode-evil-was-on t) (evil-mode -1)))
            (message (format "Switched to %s mode for the next command ..." prefix)))))

<<cmf(map="aiern-normal-state-map", mode="aiern-mode", prefix="aiern", short="a", package="aiern")>>

<<cmf(map="ryo-modal-mode-map", mode="ryo-modal-mode", prefix="ryo", short="r", package="ryo-modal")>>

<<cmf(map="sorrow-mode-map", mode="sorrow-mode", prefix="sorrow", short="s", package="sorrow")>>

<<cmf(map="evil-normal-state-map", mode="evil-mode", prefix="evil", short="e", package="evil")>>

<<cmf(map="global-map", mode="god-local-mode", prefix="god", short="g", package="god-mode")>>

<<cmf(map="xah-fly-command-map", mode="xah-fly-keys", prefix="xah", short="x", package="xah-fly-keys")>>

<<cmf(map="objed-map", mode="objed-mode", prefix="objed", short="o", package="objed")>>

<<cmf(map="modalka-mode-map", mode="modalka-mode", prefix="modalka", short="m", package="modalka")>>

<<cmf(map="lispy-mode-map", mode="lispy-mode", prefix="lispy", short="l", package="lispy")>>

(provide 'alamode)
;;; alamode.el ends here

alamode's People

Contributors

shadowrylander avatar noctuid avatar gridaphobe avatar tad-ashlock avatar justbur avatar tarleb avatar andrejlamov avatar fbergroth avatar silex avatar syohex avatar cyruseuros avatar ninrod avatar stepnem avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.