* Emacs 30.1<2025-08-11 Mon>
** early-init.el
:properties:
:header-args: :tangle ~/.emacs.d/early-init.el
:end:
*** pleasant startup with speed
#+BEGIN_SRC emacs-lisp
  ;;; init.el -*- lexical-binding: t; -*-

  ;;   Basic settings for quick startup and convenience

  ;; Startup speed, annoyance suppression
  (setq gc-cons-threshold 100000000) ; 100 mb
  (setq read-process-output-max (* 1024 1024)) ; 1mb
  (setq byte-compile-warnings '(not obsolete))
  (setq warning-suppress-log-types '((comp) (bytecomp)))
  (setq native-comp-async-report-warnings-errors 'silent)

    ;; no startup message
  (setq inhibit-startup-echo-area-message (user-login-name))

    ;; Disable startup-screen
  (setq inhibit-startup-screen -1)
  (setq inhibit-splash-screen -1)
  #+END_SRC
*** UI
#+BEGIN_SRC emacs-lisp
    ;; Default frame configuration: full screen, good-looking title bar on macOS
    (setq frame-resize-pixelwise t)
    (tool-bar-mode -1)                      ; All these tools are in the menu-bar anyway
    (setq default-frame-alist '((fullscreen . maximized)

        ;; You can turn off scroll bars by uncommenting these lines:
        ;; (vertical-scroll-bars . nil)
        ;; (horizontal-scroll-bars . nil)

        ;; Setting the face in here prevents flashes of
        ;; color as the theme gets activated
        (background-color . "#000000")
        (foreground-color . "#ffffff")
        (ns-appearance . dark)
        (ns-transparent-titlebar . t)))


    ;; Disable menu bar and scroll bar
    (menu-bar-mode -1)
    (scroll-bar-mode -1)


    ;; Increase font size
    (set-face-attribute 'default nil :height 300)

    ;; Display time
    (display-time-mode t)
    ;; Auto-refresh buffers when files on disk change.
    (global-auto-revert-mode t)

    ;; Initial-major-mode
  ;  (initial-major-mode 'fundamental-mode)

  (setq initial-scratch-message nil)
  #+END_SRC
*** uniquify
  #+BEGIN_SRC emacs-lisp
        ;; Ensure unique names when matching files exist in the buffer.
        ;; e.g. This helps when you have multiple copies of "main.rs"
        ;; open in different projects. It will add a "myproj/main.rs"
        ;; prefix when it detects matching names.
        (require 'uniquify)
        (setq uniquify-buffer-name-style 'forward)
      #+END_SRC
*** backup-files
#+BEGIN_SRC emacs-lisp
  ;; Place backups in a separate folder.
  (setq backup-directory-alist '(("." . "~/.backup"))
    backup-by-copying t    ; Don't delink hardlinks
    version-control t      ; Use version numbers on backups
    delete-old-versions t  ; Automatically delete excess backups
    kept-new-versions 2    ; how many of the newest versions to keep
    kept-old-versions 2    ; and how many of the old
    )
  (setq auto-save-file-name-transforms `((".*" "~/.saves/" t)))
#+END_SRC
*** auto-save
#+BEGIN_SRC emacs-lisp
; From http://www.emacswiki.org/emacs/AutoSave
   (defun save-buffer-if-visiting-file (&optional args)
      "Save the current buffer only if it is visiting a file"
      (interactive)
      (if (and (buffer-file-name) (buffer-modified-p))
          (save-buffer args)))

   (add-hook 'auto-save-hook 'save-buffer-if-visiting-file)

; additional parameters
(setq auto-save-interval 300
          auto-save-timeout 60)
#+END_SRC
*** emacs server
:PROPERTIES:
:CUSTOM_ID: emacs-server
:END:

=(server-start)= permits the use of =emacsclient=, =emacsclientw=, and
=org-protocol=. I used to start a server as part of my config. Now I'm
switching to using =emacs --daemon=, which starts a server
automatically. Anyway, with =--daemon=, Emacs doesn't start off in a
graphical environment, so the frames that =emacsclient -c= creates
don't get the theme applied. This fixes that:

#+begin_src emacs-lisp
(add-hook 'after-make-frame-functions
          (lambda (frame)
            (select-frame frame)
            ;(solarized-dark)
            ))
#+end_src
*** scroll-step
#+BEGIN_SRC emacs-lisp
  (setq scroll-step           1
           scroll-conservatively 10000)
#+END_SRC
*** disable bell in end
#+BEGIN_SRC emacs-lisp
;; Disable bell sound.
(setq ring-bell-function 'ignore)

;;; early-init.el ends here
#+END_SRC
** init.el
:properties:
:header-args: :tangle ~/.emacs.d/init.el
:end:
*** packages
#+BEGIN_SRC emacs-lisp
  ;;; init.el -*- lexical-binding: t; -*-

    ;;;;;;;;;;;;;;;;; Packages ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; You'll be installing your packages with the
    ;; built-in package.el script
    (require 'package)

    ;; Add MELPA to your list of package archives
    (add-to-list 'package-archives
    	         '("melpa" . "https://melpa.org/packages/"))

    (package-initialize)

    ;; Go ahead and refresh your package list to
    ;; make sure everything is up-to-date
    (unless package-archive-contents
      (package-refresh-contents))

    ; First package to install is use-package ------------------------
    (unless (package-installed-p 'use-package)
      (package-install 'use-package))


#+END_SRC
*** completion
#+BEGIN_SRC emacs-lisp
  (use-package vertico
    :ensure t
    :init
    (vertico-mode))

  (use-package marginalia
    :after vertico
    :ensure t
    :init
    (marginalia-mode))
#+END_SRC
*** savehist
#+BEGIN_SRC emacs-lisp
  (use-package savehist
    :init
    (savehist-mode))
#+END_SRC
*** theme
**** solarized-theme
#+BEGIN_SRC emacs-lisp
  (use-package solarized-theme
  :ensure t
  :config
  (load-theme 'solarized-dark t))

;(load-theme 'deeper-blue t)
#+END_SRC
*** custom-set-variables
#+BEGIN_SRC emacs-lisp
    ;;; -*- lexical-binding: t -*-
    (custom-set-variables
     ;; custom-set-variables was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.

      '(cursor-in-non-selected-windows nil)
      '(window-divider-default-places 'right-only)
      '(window-divider-default-right-width 16)
      '(x-underline-at-descent-line t))
#+END_SRC
*** custom-set-faces
#+BEGIN_SRC emacs-lisp
  (custom-set-faces
   '(default ((t (:family "Cousine" :foundry "unknown" :slant normal :weight normal :height 250 :width normal)))))
#+END_SRC
*** basic
**** ask-for-y-n-instead-of-yes-no
#+BEGIN_SRC emacs-lisp
  (fset 'yes-or-no-p 'y-or-n-p)
#+END_SRC
**** disabled-commands
#+BEGIN_SRC emacs-lisp
(put 'upcase-region 'disabled nil); C-x C-l
(put 'downcase-region 'disabled nil);   C-x C-u
#+END_SRC
**** cursor
#+BEGIN_SRC emacs-lisp

; http://emacs-fu.blogspot.in/2009/12/changing-cursor-color-and-shape.html
;; change cursor color according to mode; inspired by
;; http://www.emacswiki.org/emacs/changingcursordynamically
(setq my-read-only-color       "grey")
;; valid values are t, nil, box, hollow, bar, (bar . width), hbar,
;; (hbar. height); see the docs for set-cursor-type
(setq my-read-only-cursor-type 'hbar)
(setq my-overwrite-color       "red")
(setq my-overwrite-cursor-type 'box)
(setq my-normal-color          "white")
(setq my-normal-cursor-type    'hbar)
(defun my-set-cursor-according-to-mode ()
  "change cursor color and type according to some minor modes."
  (cond
   (buffer-read-only
    (set-cursor-color my-read-only-color)
    (setq cursor-type my-read-only-cursor-type))
   (overwrite-mode
    (set-cursor-color my-overwrite-color)
    (setq cursor-type my-overwrite-cursor-type))
   (t
    (set-cursor-color my-normal-color)
    (setq cursor-type my-normal-cursor-type))))
(add-hook 'post-command-hook 'my-set-cursor-according-to-mode)
; you can change the colors and cursor types by modifying the various variables.
;(blink-cursor-mode)			; toggle disables blinking
#+END_SRC
**** overwrite text selection
#+BEGIN_SRC emacs-lisp
;; make typing overwrite text selection
(delete-selection-mode 1)
#+END_SRC
**** utf-8
#+BEGIN_SRC emacs-lisp
  (prefer-coding-system 'utf-8)
  (setenv "LANG" "en_US.UTF-8")
#+END_SRC
**** wrap
#+BEGIN_SRC emacs-lisp
(setq fill-column nil)
;(auto-fill-mode)
;(longlines-mode)
#+END_SRC
**** global-hl-line-mode
#+BEGIN_SRC emacs-lisp
(global-hl-line-mode)
#+END_SRC
**** smooth scroll
#+BEGIN_SRC emacs-lisp
(setq scroll-step           1
         scroll-conservatively 10000)
#+END_SRC
**** column-number-mode
#+BEGIN_SRC emacs-lisp

(column-number-mode)

#+END_SRC
*** spell checking
#+BEGIN_SRC emacs-lisp
  (use-package flyspell
  :delight
  :config
  (add-hook 'text-mode-hook #'flyspell-mode)
  (add-hook 'prog-mode-hook #'flyspell-prog-mode))
#+END_SRC
*** key bindings
**** Prefix|"Name Space NS"|map initializations
***** COMMENT doc
****** URLs:
1. http://reinout.vanrees.org/weblog/2010/04/16/emacs-prefix-key.html
****** Knowledge:
******* https://www.gnu.org/software/emacs/manual/html_node/emacs/Init-Rebinding.html#Init-Rebinding


Next: Modifier Keys, Previous: Rebinding, Up: Key Bindings
48.3.6 Rebinding Keys in Your Init File

If you have a set of key bindings that you like to use all the time, you can specify them in your initialization file by writing Lisp code. See Init File, for a description of the initialization file.

There are several ways to write a key binding using Lisp. The simplest is to use the kbd function, which converts a textual representation of a key sequence—similar to how we have written key sequences in this manual—into a form that can be passed as an argument to global-set-key. For example, here's how to bind C-z to the shell command (see Interactive Shell):

     (global-set-key (kbd "C-z") 'shell)

The single-quote before the command name, shell, marks it as a constant symbol rather than a variable. If you omit the quote, Emacs would try to evaluate shell as a variable. This probably causes an error; it certainly isn't what you want.

Here are some additional examples, including binding function keys and mouse events:

     (global-set-key (kbd "C-c y") 'clipboard-yank)
     (global-set-key (kbd "C-M-q") 'query-replace)
     (global-set-key (kbd "<f5>") 'flyspell-mode)
     (global-set-key (kbd "C-<f5>") 'linum-mode)
     (global-set-key (kbd "C-<right>") 'forward-sentence)
     (global-set-key (kbd "<mouse-2>") 'mouse-save-then-kill)

Instead of using kbd, you can use a Lisp string or vector to specify the key sequence. Using a string is simpler, but only works for ASCII characters and Meta-modified ASCII characters. For example, here's how to bind C-x M-l to make-symbolic-link (see Misc File Ops):

     (global-set-key "\C-x\M-l" 'make-symbolic-link)

To put <TAB>, <RET>, <ESC>, or <DEL> in the string, use the Emacs Lisp escape sequences ‘\t’, ‘\r’, ‘\e’, and ‘\d’ respectively. Here is an example which binds C-x <TAB> to indent-rigidly (see Indentation):

     (global-set-key "\C-x\t" 'indent-rigidly)

When the key sequence includes function keys or mouse button events, or non-ASCII characters such as C-= or H-a, you can use a vector to specify the key sequence. Each element in the vector stands for an input event; the elements are separated by spaces and surrounded by a pair of square brackets. If a vector element is a character, write it as a Lisp character constant: ‘?’ followed by the character as it would appear in a string. Function keys are represented by symbols (see Function Keys); simply write the symbol's name, with no other delimiters or punctuation. Here are some examples:

     (global-set-key [?\C-=] 'make-symbolic-link)
     (global-set-key [?\M-\C-=] 'make-symbolic-link)
     (global-set-key [?\H-a] 'make-symbolic-link)
     (global-set-key [f7] 'make-symbolic-link)
     (global-set-key [C-mouse-1] 'make-symbolic-link)

You can use a vector for the simple cases too:

     (global-set-key [?\C-z ?\M-l] 'make-symbolic-link)

Language and coding systems may cause problems with key bindings for non-ASCII characters. See Init Non-ASCII.

As described in Local Keymaps, major modes and minor modes can define local keymaps. These keymaps are constructed when the mode is used for the first time in a session. If you wish to change one of these keymaps, you must use the mode hook (see Hooks).

For example, Texinfo mode runs the hook texinfo-mode-hook. Here's how you can use the hook to add local bindings for C-c n and C-c p in Texinfo mode:

     (add-hook 'texinfo-mode-hook
               (lambda ()
                 (define-key texinfo-mode-map "\C-cp"
                             'backward-paragraph)
                 (define-key texinfo-mode-map "\C-cn"
                             'forward-paragraph)))
******* http://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Keys.html
Next: Active Keymaps, Previous: Inheritance and Keymaps, Up: Keymaps
******** 22.6 Prefix Keys

A prefix key is a key sequence whose binding is a keymap. The keymap defines what to do with key sequences that extend the prefix key. For example, C-x is a prefix key, and it uses a keymap that is also stored in the variable ctl-x-map. This keymap defines bindings for key sequences starting with C-x.

******** Some of the standard Emacs prefix keys use keymaps that are also found in Lisp variables:

    esc-map is the global keymap for the <ESC> prefix key. Thus, the global definitions of all meta characters are actually found here. This map is also the function definition of ESC-prefix.
    help-map is the global keymap for the C-h prefix key.
    mode-specific-map is the global keymap for the prefix key C-c. This map is actually global, not mode-specific, but its name provides useful information about C-c in the output of C-h b (display-bindings), since the main use of this prefix key is for mode-specific bindings.
    ctl-x-map is the global keymap used for the C-x prefix key. This map is found via the function cell of the symbol Control-X-prefix.
    mule-keymap is the global keymap used for the C-x <RET> prefix key.
    ctl-x-4-map is the global keymap used for the C-x 4 prefix key.
    ctl-x-5-map is the global keymap used for the C-x 5 prefix key.
    2C-mode-map is the global keymap used for the C-x 6 prefix key.
    vc-prefix-map is the global keymap used for the C-x v prefix key.
    goto-map is the global keymap used for the M-g prefix key.
    search-map is the global keymap used for the M-s prefix key.
    facemenu-keymap is the global keymap used for the M-o prefix key.
    The other Emacs prefix keys are C-x @, C-x a i, C-x <ESC> and <ESC> <ESC>. They use keymaps that have no special names.

    The keymap binding of a prefix key is used for looking up the event that follows the prefix key. (It may instead be a symbol whose function definition is a keymap. The effect is the same, but the symbol serves as a name for the prefix key.) Thus, the binding of C-x is the symbol Control-X-prefix, whose function cell holds the keymap for C-x commands. (The same keymap is also the value of ctl-x-map.)

Prefix key definitions can appear in any active keymap. The definitions of C-c, C-x, C-h and <ESC> as prefix keys appear in the global map, so these prefix keys are always available. Major and minor modes can redefine a key as a prefix by putting a prefix key definition for it in the local map or the minor mode's map. See Active Keymaps.

If a key is defined as a prefix in more than one active map, then its various definitions are in effect merged: the commands defined in the minor mode keymaps come first, followed by those in the local map's prefix definition, and then by those from the global map.

In the following example, we make C-p a prefix key in the local keymap, in such a way that C-p is identical to C-x. Then the binding for C-p C-f is the function find-file, just like C-x C-f. The key sequence C-p 6 is not found in any active keymap.

     (use-local-map (make-sparse-keymap))
         ⇒ nil
     (local-set-key "\C-p" ctl-x-map)
         ⇒ nil
     (key-binding "\C-p\C-f")
         ⇒ find-file

     (key-binding "\C-p6")
         ⇒ nil

— Function: define-prefix-command symbol &optional mapvar prompt

    This function prepares symbol for use as a prefix key's binding: it creates a sparse keymap and stores it as symbol's function definition. Subsequently binding a key sequence to symbol will make that key sequence into a prefix key. The return value is symbol.

    This function also sets symbol as a variable, with the keymap as its value. But if mapvar is non-nil, it sets mapvar as a variable instead.

    If prompt is non-nil, that becomes the overall prompt string for the keymap. The prompt string should be given for menu keymaps (see Defining Menus).
******* http://www.emacswiki.org/emacs/DedicatedKeys
******** 1
  ; (global-set-key (kbd "<f2>") 'hippie-expand); complete
  ; (global-set-key (kbd "<f3>") 'comment-region); comment
  ; (global-set-key (kbd "<f4>") 'eval-last-sexp); eval
  ; (global-set-key (kbd "<f5>") 'set-mark-command); mark
  ; (global-set-key (kbd "<f6>") 'kill-ring-save); copy
  ; (global-set-key (kbd "<f7>") 'yank); paste
  ; (global-set-key (kbd "<f8>") 'kill-region); delete
  ; (global-set-key (kbd "<f9>") 'disk); save
  ; (global-set-key (kbd "<f10>") 'iswitchb-buffer); switch buffer
  ; (global-set-key (kbd "<f11>") 'dired); switch file
  ; (global-set-key (kbd "<f12>") 'my-kill); kill buffer
  ; (global-set-key (kbd "<print>") 'my-jump)
******** 2
(global-set-key [f1] (lambda () (interactive) (find-file "~/.xemacs/fkeys.el")))
  (global-set-key [(control f1)] (lambda () (interactive) (load-file "~/.xemacs/fkeys.el")))
  (global-set-key [(shift f1)] (lambda () (interactive) (find-file "~/.xemacs/init.el")))
  #+ignore(global-set-key [(shift f1)] (lambda () (interactive) (dired "~/.xemacs/")))
  (global-set-key [f2] 'eshell)
  (global-set-key [(control f2)] (lambda () (interactive) (eshell 1)))
  (global-set-key [f3] 'w3m)
  (global-set-key [(control f3)] 'w3m-goto-url-new-session)
  (global-set-key [(shift f3)] 'dka-w3m-goto-wiki)
  (global-set-key [f4] 'dka-switch-to-erc)
  (global-set-key [f5] 'gnus)
  (global-set-key [(control f5)]
    (lambda ()
       (interactive)
       (gnus-group-get-new-news)
       (nnmail-split-history)
       (setq nnmail-split-history nil)))
  (global-set-key [(control shift f5)]
    (lambda ()
       (interactive)
       (let ((buffer (get-buffer "*nnmail split history*")))
         (delete-windows-on buffer)
         (bury-buffer buffer))))
  (global-set-key [f6] 'calendar)
  (global-set-key [f7] 'todo-show)
  (global-set-key [f8] 'dka-tnt)
  (global-set-key [f9] 'compile)
  (global-set-key [f10] 'gdb-next)
  (global-set-key [f11] 'gdb-step)
******* http://stackoverflow.com/questions/3124844/what-are-your-favorite-global-key-bindings-in-emacs
******** 1
(global-set-key [f6] 'compile-buffer)
(global-set-key [f7] 'kmacro-start-macro-or-insert-counter)
(global-set-key [f8] 'kmacro-end-and-call-macro)
(global-set-key [f9] 'call-last-kbd-macro)
(global-set-key [f10] 'name-and-insert-last-kbd-macro)
(global-set-key [f12] 'menu-bar-open)  ; originally bound to F10
(global-set-key "\C-cR" 'rename-current-file-or-buffer)
(global-set-key "\C-cD" 'Delete-current-file-or-buffer)
******** 2
; You know, like Readline.
(global-set-key (kbd "C-M-h") 'backward-kill-word)

;; Align your code in a pretty way.
(global-set-key (kbd "C-x \\") 'align-regexp)

;; Perform general cleanup.
(global-set-key (kbd "C-c n") 'cleanup-buffer)

;; Font size
(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)

;; Use regex searches by default.
(global-set-key (kbd "C-s") 'isearch-forward-regexp)
(global-set-key (kbd "\C-r") 'isearch-backward-regexp)
(global-set-key (kbd "C-M-s") 'isearch-forward)
(global-set-key (kbd "C-M-r") 'isearch-backward)

;; Jump to a definition in the current file. (This is awesome.)
(global-set-key (kbd "C-x C-i") 'ido-imenu)

;; File finding
(global-set-key (kbd "C-x M-f") 'ido-find-file-other-window)
(global-set-key (kbd "C-x C-M-f") 'find-file-in-project)
(global-set-key (kbd "C-x f") 'recentf-ido-find-file)
(global-set-key (kbd "C-c r") 'bury-buffer)
(global-set-key (kbd "M-`") 'file-cache-minibuffer-complete)

;; Window switching. (C-x o goes to the next window)
(global-set-key (kbd "C-x O") (lambda ()
                                (interactive)
                                (other-window -1))) ;; back one
(global-set-key (kbd "C-x C-o") (lambda ()
                                  (interactive)
                                  (other-window 2))) ;; forward two

;; Indentation help
(global-set-key (kbd "C-x ^") 'join-line)
(global-set-key (kbd "C-M-\\") 'indent-region-or-buffer)

;; Start proced in a similar manner to dired
(global-set-key (kbd "C-x p") 'proced)

;; Start eshell or switch to it if it's active.
(global-set-key (kbd "C-x m") 'eshell)

;; Start a new eshell even if one is active.
(global-set-key (kbd "C-x M") (lambda () (interactive) (eshell t)))

;; Start a regular shell if you prefer that.
(global-set-key (kbd "C-x M-m") 'shell)

;; If you want to be able to M-x without meta
(global-set-key (kbd "C-x C-m") 'execute-extended-command)

;; Fetch the contents at a URL, display it raw.
(global-set-key (kbd "C-x C-h") 'view-url)

;; Help should search more than just commands
(global-set-key (kbd "C-h a") 'apropos)

;; Should be able to eval-and-replace anywhere.
(global-set-key (kbd "C-c e") 'eval-and-replace)

;; Magit rules!
(global-set-key (kbd "C-x g") 'magit-status)

;; This is a little hacky since VC doesn't support git add internally
(eval-after-load 'vc
  (define-key vc-prefix-map "i" '(lambda () (interactive)
                                   (if (not (eq 'Git (vc-backend buffer-file-name)))
                                       (vc-register)
                                     (shell-command (format "git add %s" buffer-file-name))
                                     (message "Staged changes.")))))

;; Activate occur easily inside isearch
(define-key isearch-mode-map (kbd "C-o")
  (lambda () (interactive)
    (let ((case-fold-search isearch-case-fold-search))
      (occur (if isearch-regexp isearch-string (regexp-quote isearch-string))))))

;; Org
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)

;; program shortcuts - s stands for windows key(super)
(global-set-key (kbd "s-b") 'browse-url)          ;; Browse (W3M)
(global-set-key (kbd "s-f") 'browse-url-firefox)  ;; Firefox...
(global-set-key (kbd "s-l") 'linum-mode)          ;; show line numbers in buffer
(global-set-key (kbd "s-r") 're-builder)          ;; build regular expressions

;; Super + uppercase letter signifies a buffer/file
(global-set-key (kbd "s-S")                       ;; scratch
                (lambda()(interactive)(switch-to-buffer "*scratch*")))
(global-set-key (kbd "s-E")                       ;; .emacs
                (lambda()(interactive)(find-file "~/emacs/dot-emacs.el")))

;; cycle through buffers
(global-set-key (kbd "<C-tab>") 'bury-buffer)

;; use hippie-expand instead of dabbrev
(global-set-key (kbd "M-/") 'hippie-expand)

;; spell check Bulgarian text
(global-set-key (kbd "C-c B")
                (lambda()(interactive)
                  (ispell-change-dictionary "bulgarian")
                  (flyspell-buffer)))

;; replace buffer-menu with ibuffer
(global-set-key (kbd "C-x C-b") 'ibuffer)

;; interactive text replacement
(global-set-key (kbd "C-c C-r") 'iedit-mode)

;; swap windows
(global-set-key (kbd "C-c s") 'swap-windows)

;; duplicate the current line or region
(global-set-key (kbd "C-c d") 'duplicate-current-line-or-region)

;; rename buffer & visited file
(global-set-key (kbd "C-c r") 'rename-file-and-buffer)

;; open an ansi-term buffer
(global-set-key (kbd "C-x t") 'visit-term-buffer)

;; macros
(global-set-key [f10]  'start-kbd-macro)
(global-set-key [f11]  'end-kbd-macro)
(global-set-key [f12]  'call-last-kbd-macro)

(provide 'bindings-config)
******* https://raw.githubusercontent.com/filsinger/emacs-config/master/key-bindings.el
;; ================================================
;; Key Configurations
;; ================================================

;; Unset keys
(global-set-key "\C-z" nil)                   ; disable CTRL+z
(global-unset-key "\C-z")                     ; disable CTRL+z
(global-unset-key (kbd "C-."))
(global-unset-key (kbd "C-,"))

(when (eq window-system nil) (global-set-key "\C-d" 'backward-delete-char)) ; make sure backspace works the way I like in the OSX terminal
(global-set-key (kbd "S-<return>") 'smart-open-line) ; bind S-return to create a new indented line below the current line
(global-set-key (kbd "C-c C-c") 'comment-or-uncomment-region) ; bind C-u to comment toggle
(global-set-key (kbd "C-c a") 'align-entire) ; bind C-a to align-entire
(global-set-key (kbd "M-s") 'sort-lines)     ; bind m-s to sort-lines
(global-set-key (kbd "C-S-s") 'tags-apropos) ; tags apropos
(global-set-key (kbd "C-.") 'next-multiframe-window) ; use C-. to move to the next window
(global-set-key (kbd "C-,") 'previous-multiframe-window) ; use C-, to move to the previous window
(global-set-key (kbd "C-{") 'switch-to-prev-buffer) ; use C-{ to switch to the previous buffer
(global-set-key (kbd "C-}") 'switch-to-next-buffer) ; use C-} to switch to the next buffer

(when (eq system-type 'darwin)
  (global-set-key (kbd "<kp-delete>") 'delete-region-or-char)) ; bind delete to delete-region-or-char

;; highlight-symbol
(global-set-key (kbd "C-<f3>") 'highlight-symbol-at-point)
(global-set-key (kbd "<f3>")   'highlight-symbol-next)
(global-set-key (kbd "S-<f3>") 'highlight-symbol-prev)
(global-set-key (kbd "M-<f3>") 'highlight-symbol-perv)

;; killing
(global-set-key (kbd "C-M-k") 'kill-symbol)            ; bind kill-symbol to C-M-k
(global-set-key (kbd "C-M-S-k") 'kill-smartly)         ; bind kill-smartly to C-M-S-k

;; spelling
(global-set-key (kbd "<f8>") 'ispell-word) ; spell-check the current word

;; helm
;;(global-set-key (kbd "C-x C-a") 'helm-mini)

;; multiple-cursors
(global-set-key (kbd "C-x r t") 'mc/edit-lines)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-M-m") 'mc/mark-all-like-this) ; like the other two, but takes an argument (negative is previous)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C-S-c C-e") 'mc/edit-ends-of-lines)
(global-set-key (kbd "C-S-c C-a") 'mc/edit-beginnings-of-lines)

;; region
(global-set-key (kbd "C-c e") 'eval-and-replace)       ; evaluate and replace the region
(global-set-key (kbd "C-#") 'er/expand-region)         ; expand-region
(global-set-key (kbd "C-!") 'mark-between-parentheses) ; mark-between-parentheses

;; navigation
(global-set-key "\M-g-g" 'goto-line)                   ; move cursor to a specific line
(global-set-key (kbd "<home>") 'beginning-of-line)     ; move cursor to the begenning of the line
(global-set-key (kbd "<end>") 'end-of-line)            ; move cursor to the end of the line
(global-set-key (kbd "C-<home>") 'beginning-of-buffer) ; move cursor to the begenning of the buffer
(global-set-key (kbd "C-<end>") 'end-of-buffer)        ; move cursor to the end of the buffer
(global-set-key (kbd "<C-M-down>") 'move-line-down)    ; move current line up
(global-set-key (kbd "<C-M-up>") 'move-line-up)        ; move current line down
(global-set-key (kbd "C-;") 'ido-imenu)
(global-set-key (kbd "C-c SPC") 'ace-jump-mode)        ; move cursor via ace-jump-mode
(global-set-key (kbd "C-<left>") 'backward-word)       ; move backward word
(global-set-key (kbd "C-<right>") 'forward-word)       ; move forward word
(global-set-key (kbd "C-S-<left>") 'backward-sexp)     ; move backward sexp
(global-set-key (kbd "C-S-<right>") 'forward-sexp)     ; move forward sexp
(global-set-key [remap move-beginning-of-line] 'smarter-move-beginning-of-line) ;; remap C-a to `smarter-move-beginning-of-line'

;; transpose key bindings
(global-unset-key (kbd "M-t"))      ; unbind the default transpose-words keybinding
(global-set-key (kbd "M-t c") 'transpose-chars)
(global-set-key (kbd "M-t l") 'transpose-lines)
(global-set-key (kbd "M-t p") 'transpose-paragraphs)
(global-set-key (kbd "M-t s") 'transpose-sexps)
(global-set-key (kbd "M-t w") 'transpose-words)

;; file finding
(global-set-key (kbd "C-x C-f") 'ido-find-file)              ; use ido to find file and open in the current window.
(global-set-key (kbd "C-x M-f") 'ido-find-file-other-window) ; use ido to find file and open in the other window.
(global-set-key (kbd "C-c r") 'revert-buffer)                ; revert the current buffer.
(global-set-key (kbd "C-x C-b") 'ibuffer-other-window)       ; use ibuffer instead of the default buffer-menu.
(global-set-key (kbd "C-c o") 'ff-get-other-file)            ; find compainion file.
(add-hook 'dired-mode-hook
          (lambda ()
            (put 'dired-find-alternate-file 'disabled nil)
            (define-key dired-mode-map (kbd "^") (lambda () (interactive) (find-alternate-file ".."))) ; dired will reuse the same buffer when using ^ to navigate to the parent directory
            (define-key dired-mode-map (kbd "<return>") (lambda () (interactive) (if (file-directory-p (dired-file-name-at-point)) (dired-find-alternate-file) (dired-find-file)))) ; make <return> open a new directory in the current buffer
            (define-key dired-mode-map (kbd "C-<return>") (lambda () (interactive) (dired-find-file))) ; C-<return> will always use dired-find-file
            ))

;; smex (like ido for M-x)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)

;;
(global-set-key (kbd "M-_") 'camelscore-word-at-point)

;; yasnippet
(global-set-key (kbd "C-'") 'yas-insert-snippet)

;; mode keymap rebinding
(eval-after-load "ibuffer"              ; rebind ibuffer keys
  '(progn
     (define-key ibuffer-mode-map (kbd "C-x C-f") 'ibuffer-ido-find-file)))
(eval-after-load "flyspell"				; rebind flyspell keys
  '(progn
     (define-key flyspell-mode-map (kbd "C-,") nil)
     (define-key flyspell-mode-map (kbd "C-.") nil)
     (define-key flyspell-mode-map (kbd "<f7>") 'flyspell-goto-next-error)))
(eval-after-load "org"					; rebind org keys (i use C-, and C-. to switch windows)
  '(progn
     (define-key org-mode-map (kbd "C-,") nil)
     (define-key org-mode-map (kbd "C-.") nil)))
(eval-after-load "zencoding-mode"
  '(progn
     (define-key zencoding-mode-keymap (kbd "<C-return>") 'zencoding-expand-line)
     ))
(eval-after-load "w3m"
  '(progn
     (define-key w3m-mode-map (kbd "C-M-<down>") 'w3m-next-anchor)
     (define-key w3m-mode-map (kbd "C-M-<up>") 'w3m-previous-anchor)
     (define-key w3m-mode-map (kbd "C-M-<left>") 'w3m-view-previous-page)
     (define-key w3m-mode-map (kbd "C-M-<right>") 'w3m-view-this-url)

     (define-key w3m-mode-map (kbd "<down>") nil)
     (define-key w3m-mode-map (kbd "<up>") nil)
     (define-key w3m-mode-map (kbd "<left>") nil)
     (define-key w3m-mode-map (kbd "<right>") nil)

     )
  )

;; compiling
(global-set-key (kbd "<f7>") 'compile)            ; compile

;; ================================================
;; terminal-only settings
;; ================================================
(unless window-system
  ;; enable mouse support
  (require 'mouse)
  (xterm-mouse-mode t)
  (global-set-key [mouse-4] '(lambda ()
                              (interactive)
                              (scroll-down 1)))
  (global-set-key [mouse-5] '(lambda ()
                              (interactive)
                              (scroll-up 1)))
  (defun track-mouse (e))
  (setq mouse-sel-mode t)

  ;; input decode map
  (define-key input-decode-map "\e[1;0A" [M-S-up])
  (define-key input-decode-map "\e[1;0B" [M-S-down])
  (define-key input-decode-map "\e[1;0C" [M-S-right])
  (define-key input-decode-map "\e[1;0D" [M-S-left])
  (define-key input-decode-map "\e[1;2A" [S-up])
  (define-key input-decode-map "\e[1;2B" [S-down])
  (define-key input-decode-map "\e[1;2C" [S-right])
  (define-key input-decode-map "\e[1;2D" [S-left])
  (define-key input-decode-map "\e[1;3A" [M-up])
  (define-key input-decode-map "\e[1;3B" [M-down])
  (define-key input-decode-map "\e[1;3C" [M-right])
  (define-key input-decode-map "\e[1;3D" [M-left])
  (define-key input-decode-map "\e[1;5A" [C-up])
  (define-key input-decode-map "\e[1;5B" [C-down])
  (define-key input-decode-map "\e[1;5C" [C-right])
  (define-key input-decode-map "\e[1;5D" [C-left])
  (define-key input-decode-map "\e[1;6A" [C-S-up])
  (define-key input-decode-map "\e[1;6B" [C-S-down])
  (define-key input-decode-map "\e[1;6C" [C-S-right])
  (define-key input-decode-map "\e[1;6D" [C-S-left])
)
;; ================================================

(provide 'key-bindings)
******* Good Spots for User Defined Keys: Table: http://ergoemacs.org/emacs/keyboard_shortcuts.html:

|------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Keys                                     | Comment                                                                                                                                                                                                                 |
| <20>                                     | <40>                                                                                                                                                                                                                    |
|------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| F5, F6, F7, F8, F9, F11, F12             | Excellent                                                                                                                                                                                                               |
| F1, F2, F3, F4, F10, F11                 | Good if you don't use their defaults actions.                                                                                                                                                                           |
| Ctrl+F1 to Ctrl+F12                      | Excellent (be sure they are not used by the OS)                                                                                                                                                                         |
| Alt+F1 to Alt+F12                        | Excellent. (be sure they are not used by the OS)                                                                                                                                                                        |
| Shift+F1 to Shift+F12                    | Excellent                                                                                                                                                                                                               |
| Ctrl+0 to Ctrl+9, Alt+0 to Alt+9         | Excellent, if you don't use their default action. By default they are digit-argument. Use universal-argument 【Ctrl+u】 for digit argument instead.                                                                     |
| Keys on number pad, with(out) a modifier | Very useful, but depending on which emacs distro/OS you are using, or terminal vs GUI, binding these keys may not work. Same thing can be said for those {Insert, ⌦ Delete, ↖ Home, ↘ End, ⇞ Page △, ⇟ Page ▽, …} keys. |
| Hyper or Super                           | Any combination with these is good. You can set them to ❖ Win or ▤ Menu or ⌥ Opt. 〔➤ How to Define Super ＆ Hyper Keys〕                                                                                               |
|------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
***** Abstract
****** f1
1. "Key-foo f1" gives all bindings with Key-foo as prefix.
2. Hence never assign "key f1". Except "C-S-".
****** Not definable
1. C-S-f4 is not definable! Converts mouse pointer into a cross.
****** Not usable in sequence
1. f2: being C-x
2. f3: being C-c
****** My name spaces
1. "Double Click" Name Spaces (or Prefix) such as F5F5, F6F6, F7F7 etc and others F5F4, F4F3 etc. are on top in listing.
***** Table
Initial = initial function of the key
Relocation = final key of initial function

"C-c TAB" (org-table-toggle-column-width): Shrink or expand current column.

|     | <20>                                                                                             |            |             |
| Key | Initial                                                                                          | Relocation | Final NS    |
|-----+--------------------------------------------------------------------------------------------------+------------+-------------|
| CL  | Capslock                                                                                         |            | f13         |
| f2  | <f2> 2: 2C-two-columns, <f2> b: 2C-associate-buffer, <f2> s: 2C-split, <f2> <f2>: 2C-two-columns |            | C-x         |
| f3  | (kmacro-start-macro-or-insert-counter ARG)                                                       |            | C-c         |
| f4  | (kmacro-end-or-call-macro ARG &optional NO-REPEAT)                                               |            | my web      |
| f5  |                                                                                                  |            |             |
| f6  |                                                                                                  |            | org-mode    |
| f7  |                                                                                                  |            | programming |
| f8  |                                                                                                  |            | speedbar    |
| f9  |                                                                                                  |            |             |
| f10 | menu-bar-open                                                                                    | f10 f10    |             |
| f11 | toggle-frame-fullscreen &optional FRAME                                                          | f11 f11    |             |
| f12 |                                                                                                  |            |             |
***** def
****** CL = Capslock => f13
#+BEGIN_SRC emacs-lisp
; Bind Caps-Lock to M-x ;; http://sachachua.com/wp/2008/08/04/emacs-caps-lock-as-m-x/
; of course, this disables normal Caps-Lock for *all* apps
(if (eq window-system 'x)
    (shell-command "xmodmap -e 'clear Lock' -e 'keycode 66 = F13'"))

;(global-set-key [f13] 'org-ctrl-c-ctrl-c)

(define-prefix-command 'mylocal-f13-bindings-keymap)
(global-set-key [(f13)] 'mylocal-f13-bindings-keymap)

(define-prefix-command 'mylocal-f13f13-bindings-keymap)
(global-set-key [(f13)(f13)] 'mylocal-f13f13-bindings-keymap)
#+END_SRC
****** f2 => C-x
#+BEGIN_SRC emacs-lisp
(define-key global-map (kbd "<f2>") ctl-x-map)
#+END_SRC
****** f3 => C-c
#+BEGIN_SRC emacs-lisp
(define-key key-translation-map (kbd "<f3>") (kbd "C-c"))
#+END_SRC
****** f4
#+BEGIN_SRC emacs-lisp
  (define-prefix-command 'mylocal-f4-bindings-keymap)
  (global-set-key [(f4)] 'mylocal-f4-bindings-keymap)

  (define-prefix-command 'mylocal-f4f4-bindings-keymap)
  (global-set-key [(f4)(f4)] 'mylocal-f4f4-bindings-keymap)

  (define-prefix-command 'mylocal-f4e-bindings-keymap)
  (global-set-key [(f4) e] 'mylocal-f4e-bindings-keymap)
#+END_SRC
****** C-s
#+BEGIN_SRC emacs-lisp
  (define-prefix-command 'mylocal-C-s-bindings-keymap)
  (global-set-key [(C-s)] 'mylocal-C-s-bindings-keymap)
#+END_SRC
****** f5
#+BEGIN_SRC emacs-lisp
  (define-prefix-command 'mylocal-f5-bindings-keymap)
  (global-set-key [(f5)] 'mylocal-f5-bindings-keymap)

  (define-prefix-command 'mylocal-f5f5-bindings-keymap)
  (global-set-key [(f5)(f5)] 'mylocal-f5f5-bindings-keymap)
#+END_SRC
****** f6 org-mode
#+BEGIN_SRC emacs-lisp
  (define-prefix-command 'mylocal-f6-bindings-keymap)
  (global-set-key [(f6)] 'mylocal-f6-bindings-keymap)

  ; org: copy, paste, kill
  (define-prefix-command 'mylocal-f6f6-bindings-keymap)
  (global-set-key [(f6)(f6)] 'mylocal-f6f6-bindings-keymap)

  ; org: table
  (define-prefix-command 'mylocal-f6f5-bindings-keymap)
  (global-set-key [(f6)(f5)] 'mylocal-f6f5-bindings-keymap)

  ; org: agenda
  (define-prefix-command 'mylocal-f66-bindings-keymap)
  (global-set-key [(f6) 6] 'mylocal-f66-bindings-keymap)

  ; org: export
  (define-prefix-command 'mylocal-f67-bindings-keymap)
  (global-set-key [(f6) 7] 'mylocal-f67-bindings-keymap)

  ; org: babel
  (define-prefix-command 'mylocal-f6f7-bindings-keymap)
  (global-set-key [(f6)(f7)] 'mylocal-f6f7-bindings-keymap)
#+END_SRC
****** f7 programming
#+BEGIN_SRC emacs-lisp
  (define-prefix-command 'mylocal-f7-bindings-keymap)
  (global-set-key [(f7)] 'mylocal-f7-bindings-keymap)

  (define-prefix-command 'mylocal-f7f7-bindings-keymap)
  (global-set-key [(f7)(f7)] 'mylocal-f7f7-bindings-keymap)

  (define-prefix-command 'mylocal-f7f7c-bindings-keymap)
  (global-set-key [(f7)(f7)(c)] 'mylocal-f7f7c-bindings-keymap)
#+END_SRC
****** f8 speedbar
#+BEGIN_SRC emacs-lisp
  (define-prefix-command 'mylocal-f8-bindings-keymap)
  (global-set-key [(f8)] 'mylocal-f8-bindings-keymap)

  (define-prefix-command 'mylocal-f8f8-bindings-keymap)
  (global-set-key [(f8)(f8)] 'mylocal-f8f8-bindings-keymap)
#+END_SRC
****** f10
#+BEGIN_SRC emacs-lisp
  (define-prefix-command 'mylocal-f10-bindings-keymap)
  (global-set-key [(f10)] 'mylocal-f10-bindings-keymap)
#+END_SRC
****** f11
#+BEGIN_SRC emacs-lisp
  (define-prefix-command 'mylocal-f11-bindings-keymap)
  (global-set-key [(f11)] 'mylocal-f11-bindings-keymap)
#+END_SRC
****** f12
#+BEGIN_SRC emacs-lisp
  (define-prefix-command 'mylocal-f12-bindings-keymap)
  (global-set-key [(f12)] 'mylocal-f12-bindings-keymap)
#+END_SRC
**** Sequences (not chords): M, C, s, CL=Capslock(f13), f5-8
***** M-s: org
****** M-s-return: insert "Abstract" outline below
#+BEGIN_SRC emacs-lisp
(defun zM-s-return ()
  (interactive)
  (org-end-of-line)
  (org-return)
  (insert "Abstract")
  (org-beginning-of-line)
  (org-meta-return)
  (org-metaright))

(global-set-key (kbd "M-s-<return>") 'zM-s-return)
#+END_SRC
***** C
****** C-
******* navigate to top/end of buffer
#+BEGIN_SRC emacs-lisp
(global-set-key [\C-home] 'beginning-of-buffer)
(global-set-key [\C-end] 'end-of-buffer)
#+END_SRC
******* font size increase/decrease:
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-=") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
#+END_SRC

****** C-S: general
******* C-S-escape: undo
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-S-<escape>") 'undo)
#+END_SRC
******* C-~: 'unbury-buffer
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-~") 'unbury-buffer)
#+END_SRC

******* C-S-Tab: bury-buffers
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<C-S-iso-lefttab>") 'bury-buffer)
#+END_SRC

******* C-!: delete-window
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-!") 'delete-window)
#+END_SRC

******* C-S-f1: delete-other-windows
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-S-<f1>") 'delete-other-windows)
#+END_SRC

******* C-S-f2: ibuffer menu
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-S-<f2>") 'ibuffer)
#+END_SRC

******* C-S-f3: bookmark+: list/edit
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-S-<f3>") 'bookmark-bmenu-list)
#+END_SRC

******* C-$: cycle-my-theme
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-$") 'zcycle-my-theme)
#+END_SRC

******* C-(: kmacro-start-macro
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-(") 'kmacro-start-macro)
; This was F3 by default in Emacs. Now F3 is used for C-c by me.
#+END_SRC

******* C-): kmacro-end-macro
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-)") 'kmacro-end-macro)
#+END_SRC

******* C-*: kmacro-end-and-call-macro
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-*") 'kmacro-end-and-call-macro)
#+END_SRC

******* C-|: org-table-create-or-convert-from-region
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-|") 'org-table-create-or-convert-from-region)
#+END_SRC

****** C-s: org
******* C-s-up: org-narrow-to-subtree
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-s-<up>") 'org-narrow-to-subtree)
#+END_SRC
******* C-s-down: org-widen
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-s-<down>") 'widen)
#+END_SRC

******* C-s-right: org-cycle
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-s-<right>") 'toggle-truncate-lines)
#+END_SRC

******* C-s-left: org-shifttab
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-s-<left>") 'toggle-truncate-lines)
#+END_SRC
***** CL=Capslock(f13): NOT ALL RUNNING WELL!
****** CL-<left=p|down=f|up=u|right=n>:
#+BEGIN_SRC emacs-lisp

(global-set-key (kbd "<f13> <down>") 'query-replace)
(global-set-key (kbd "<f13> <up>") (kbd "C-g")); 'keyboard-quit


(global-set-key (kbd "<f13> <right>") 'isearch-forward)
(global-set-key (kbd "<f13> <left>") 'isearch-backward)

(defun zlocal-isearch-hook ()
  "Hook for `isearch-mode-hook' "
  (define-key isearch-mode-map (kbd "<f13> <left>") 'isearch-repeat-backward)
  (define-key isearch-mode-map (kbd "<f13> <right>") 'isearch-repeat-forward))

(add-hook 'isearch-mode-hook 'zlocal-isearch-hook)


(defun zlocal-km () ;(lambda (&optional arg)
                       "Keyboard macro."
  ((interactive "p") (kmacro-exec-ring-item (quote ([home S-end 134217765 124 return 17 10 return 33 s-left] 0 "%d")))))

(global-set-key (kbd "<f13> m 1") 'zlocal-km)
#+END_SRC
***** s: super
****** s-s: save-buffer
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "s-s") 'save-buffer)
#+END_SRC
****** wrap without splitting words
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "s-v") 'visual-line-mode)
#+END_SRC
****** org
******* s-<left=p|down=f|up=u|right=n>: org tree navigations
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<s-left>") 'outline-previous-visible-heading)
(global-set-key (kbd "<s-up>") 'outline-up-heading)
(global-set-key (kbd "<s-down>") 'org-forward-heading-same-level)
(global-set-key (kbd "<s-right>") 'outline-next-visible-heading)

#+END_SRC
******* s-return: from beginning, insert outline below
#+BEGIN_SRC emacs-lisp
(defun zs-return ()
"Insert outline below, from beginning, from any where in the current outline."
(interactive)
(org-beginning-of-line)
(org-meta-return))

(global-set-key (kbd "s-<return>") 'zs-return)

#+END_SRC
***** f4: web
****** name spaces
******* F4 e: eww
******** f4 e e: eww URL
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f4> e e") 'eww)
#+END_SRC

******** f4 e f: eww file
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f4> e f") 'eww-open-file)
#+END_SRC
***** f5: general
****** name spaces
******* F5 F4: ansi-term, (e)shell
******** f5 f4 f4: split-window-below and shell
#+BEGIN_SRC emacs-lisp
(defun zf5f4f4 ()
  "split-window-below and shell"
  (interactive)
  (split-window-below) (other-window 1) (shell))


(global-set-key (kbd "<f5> <f4> <f4>") 'zf5f4f4)

#+END_SRC
******** f5 f4 3: split-window-below and ansi-term
#+BEGIN_SRC emacs-lisp
(defun zf5f43 ()
  "split-window-below and ansi-term"
  (interactive)
  (split-window-below)
  (other-window 1)
  (ansi-term "/bin/sh"))


(global-set-key (kbd "<f5> <f4> 3") 'zf5f43)

#+END_SRC

******** f5 f4 4: split-window-below and eshell
#+BEGIN_SRC emacs-lisp
(defun zf5f44 ()
  "split-window-below and eshell"
  (interactive)
  (split-window-below) (other-window 1) (eshell))


(global-set-key (kbd "<f5> <f4> 4") 'zf5f44)

#+END_SRC
******* F5 F5: Copy, Kill general, menu-bar, ispell, query-replace, customize-group, linum
******** f5 f5 del: kill-line = C-k
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <f5> <delete>") 'kill-line)
#+END_SRC

******** f5 f5 f4: Backwards kill text from-point-to-beginning-of-line
Idea from http://www.macroexpand.com/~bm3719/_emacs.html

#+BEGIN_SRC emacs-lisp
(defun zptbolc ()
  (interactive)
  (kill-line 0))

(global-set-key (kbd "<f5> <f5> <f4>") 'zptbolc)
#+END_SRC

******** f5 f5 f5: copy region = kill-ring-save = M-w
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <f5> <f5>") 'kill-ring-save)
#+END_SRC

******** f5 f5 f6: paste = 'yank = C-y
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <f5> <f6>") 'yank)
#+END_SRC

******** f5 f5 f8: kill-region = cut
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <f5> <f8>") 'kill-region)
#+END_SRC

******** f5 f5 f10: menu-bar-mode
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <f5> <f10>") 'menu-bar-mode)
#+END_SRC
******** f5 f5 4: ispell-word
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <f5> 4") 'ispell-word)
#+END_SRC

******** f5 f5 5: query-replace
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <f5> 5") 'query-replace)
#+END_SRC

******** f5 f5 c: customize-group
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <f5> c") 'customize-group)
#+END_SRC

******** f5 f5 l: linum-mode
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <f5> l") 'linum-mode)
#+END_SRC
****** direct
******* f5 6: sort-lines
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> 6") 'sort-lines)
#+END_SRC
******* f5 up|down: other-window
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <up>") 'other-window)
(global-set-key (kbd "<f5> <down>") 'other-window)
#+END_SRC

******* f5 left|right: winner-undo|redo
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> <left>") 'winner-undo)
(global-set-key (kbd "<f5> <right>") 'winner-redo)
#+END_SRC
******* f5 a: auto-fill-mode
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> a") 'auto-fill-mode)
#+END_SRC

******* f5 c: calendar
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> c") 'calendar)
#+END_SRC
******* f5 d: insert date-time
#+BEGIN_SRC emacs-lisp
; Insert a UTC datetime string in ISO 8601 format.
(defun zdt ()
  "Insert an ISO 8601 formatted datetime string, with time in UTC."
  (interactive)
  (insert (format-time-string "%Y-%m-%d %H:%M:%S" nil 1)))

(global-set-key (kbd "<f5> d") 'zdt)
#+END_SRC
******* f5 e:  restart-emacs
#+BEGIN_SRC emacs-lisp
  ;  (defun reload-dotemacs-file ()
  ;    (interactive) (load-file "~/.emacs"))

  ; This works OK, but is longer!; (define-key mylocal-f5 bindings-keymap (vector ?d) 'reload-dotemacs-file)
  ;(global-set-key (kbd "<f5> e") 'reload-dotemacs-file)

  (global-set-key (kbd "<f5> e") 'restart-emacs)
#+END_SRC

******* f5 g: goto-line
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> g") 'goto-line) ;from http://www.sci.utah.edu/~cscheid/software/cscheid.emacs
#+END_SRC

******* f5 l: linum-mode
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> l") 'linum-mode)
#+END_SRC

******* f5 p: package-list-packages
#+BEGIN_SRC emacs-lisp
(defun zf5p ()
  (interactive)
  (copy-file "~/.emacs" "~/.emacs.o" 1)
  (package-list-packages))

(global-set-key (kbd "<f5> p") 'zf5p)
#+END_SRC

#+RESULTS:
: zf5p

******* f5 u: customize
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f5> u") 'customize)
#+END_SRC
***** f6: org
****** F6 F5: Table
****** F6 F6: Copy, Kill Org
******* f6 f6 del: org-kill-line-from-beginning
#+BEGIN_SRC emacs-lisp
(defun zoklfb ()
  "org-kill-line-from-beginning"
  (interactive)
  (org-beginning-of-line)
  (org-kill-line))

(global-set-key (kbd "<f6> <f6> <delete>") 'zoklfb)
#+END_SRC
******* f6 f6 f5: org-copy-special
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f6> <f6> <f5>") 'org-copy-special)
#+END_SRC
******* f6 f6 f6: org-yank = paste
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f6> <f6> <f6>") 'org-mode)
#+END_SRC

******* f6 f6 f7: org-copy-visible
(global-set-key (kbd "<f6> <f6> <f7>") 'org-copy-visible)
****** F6 F7: Babel
******* f6 f7 t: org-babel-tangle
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f6> <f7> t") 'org-babel-tangle)
#+END_SRC
****** F6 6: Agenda
****** F6 7: Export
****** direct
******* f6 d: visit dotemacs org lp
#+BEGIN_SRC emacs-lisp
(defun zvfd ()
(interactive)
(find-file "~/prog/zzmy/emacs/dotemacs/lp/dotemacs.org") )

(global-set-key (kbd "<f6> d") 'zvfd)
#+END_SRC

******* f6 i: org-indent-mode
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f6> i") 'org-indent-mode)
#+END_SRC
***** f7: programming
****** name spaces
******* F7 F7 Name Space: comment-region|Snippets|kmacro
******** F7 F7 c Name Space: comment-region
********* f7 f7 c 3: comment region with "#"
#+BEGIN_SRC emacs-lisp
 (global-set-key (kbd "<f7> <f7> c 3") 'comment-region)
#+END_SRC

******** f7 f7 f7: eval-last-sexp
#+BEGIN_SRC emacs-lisp
 (global-set-key (kbd "<f7> <f7> <f7>") 'eval-last-sexp)
#+END_SRC
******** t f7 f7 e: emacs lisp
#+BEGIN_SRC emacs-lisp
;  (defun zf7f7e ()
;    (interactive)
;    (newline-and-indent)

;    (insert
;      "#+BEGIN_SRC emacs-lisp
;      (defun zf7f7e ()
;        (interactive))

;      (global-set-key (kbd "<f7> <f7> e") 'zf7f7e
; ##+END_SRC")

;    (global-set-key (kbd "<f7> <f7> e") 'zf7f7e)

#+END_SRC

******** f7 f7 g: gnuplot-make-buffer
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f7> <f7> g") 'gnuplot-make-buffer)
#+END_SRC
******** t f7 f7 y n: new yasnippet: C-c & C-n
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f7> <f7> y n") 'yas-new-snippet)
#+END_SRC

******** t f7 f7 y s: insert yasnippet: C-c & C-s
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f7> <f7> y s") 'yas-insert-snippet)
#+END_SRC

******** t f7 f7 y v: visit yasnippet file
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f7> <f7> y v") 'yas-visit-snippet-file)
#+END_SRC

****** direct
******* f7 i: indent-sexp
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f7> i") 'indent-sexp)
#+END_SRC
******* f7 r: inf-ruby
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f7> r") 'inf-ruby)
#+END_SRC
***** f8: file system: bookmark+|deft|dir|dired|recentf|sunrise
****** COMMENT Help
******* Enabled minor modes:
Auto-Composition Auto-Compression Auto-Encryption
Blink-Cursor Delete-Selection Display-Time File-Name-Shadow Font-Lock
Global-Font-Lock Hl-Line Icomplete Line-Number Mouse-Wheel Read-Only
Recentf Shell-Dirtrack Show-Paren Sr-Modelie Sr-Popviewer Sr-Tabs
Tooltip Transient-Mark Winner

(Information about these minor modes follows the major mode info.)

******* Sunrise Commander mode defined in `sunrise-commander.el':
Two-pane file manager for Emacs based on Dired and inspired by MC.

******* The following keybindings are available:

        /, j .......... go to directory
        p, n .......... move cursor up/down
        M-p, M-n ...... move cursor up/down in passive pane
        ^, J .......... go to parent directory
        M-^, M-J ...... go to parent directory in passive pane
        Tab ........... switch to other pane
        C-Tab.......... switch to viewer window
        C-c Tab ....... switch to viewer window (console compatible)
        RET, f ........ visit selected file/directory
        M-RET, M-f .... visit selected file/directory in passive pane
        C-c RET ....... visit selected in passive pane (console compatible)
        b ............. visit selected file/directory in default browser
        F ............. visit all marked files, each in its own window
        C-u F ......... visit all marked files in the background
        o,v ........... quick visit selected file (scroll with C-M-v, C-M-S-v)
        C-u o, C-u v .. kill quick-visited buffer (restores normal scrolling)
        X ............. execute selected file
        C-u X.......... execute selected file with arguments

        + ............. create new directory
        M-+ ........... create new empty file(s)
        C ............. copy marked (or current) files and directories
        R ............. rename marked (or current) files and directories
        D ............. delete marked (or current) files and directories
        S ............. soft-link selected file/directory to passive pane
        Y ............. do relative soft-link of selected file in passive pane
        H ............. hard-link selected file to passive pane
        K ............. clone selected files and directories into passive pane
        M-C ........... copy (using traditional dired-do-copy)
        M-R ........... rename (using traditional dired-do-rename)
        M-D ........... delete (using traditional dired-do-delete)
        M-S............ soft-link (using traditional dired-do-symlink)
        M-Y............ do relative soft-link (traditional dired-do-relsymlink)
        M-H............ hard-link selected file/directory (dired-do-hardlink)
        A ............. search marked files for regular expression
        Q ............. perform query-replace-regexp on marked files
        C-q ........... search occurrences of a string in marked files
        C-c s ......... start a "sticky" interactive search in the current pane

        M-a ........... move to beginning of current directory
        M-e ........... move to end of current directory
        M-y ........... go to previous directory in history
        M-u ........... go to next directory in history
        C-M-y ......... go to previous directory in history on passive pane
        C-M-u ......... go to next directory in history on passive pane

        g, C-c C-c .... refresh pane
        s ............. sort entries (by name, number, size, time or extension)
        r ............. reverse the order of entries in the active pane (sticky)
        C-o ........... show/hide hidden files (requires dired-omit-mode)
        C-Backspace ... hide/show file attributes in pane
        C-c Backspace . hide/show file attributes in pane (console compatible)
        y ............. show file type / size of selected files and directories.
        M-l ........... truncate/continue long lines in pane
        C-c v ......... put current panel in VIRTUAL mode
        C-c C-v ....... create new pure VIRTUAL buffer
        C-c C-w ....... browse directory tree using w3m

        M-t ........... transpose panes
        M-o ........... synchronize panes
        C-c C-s ....... change panes layout (vertical/horizontal/top-only)
        [ ............. enlarges the right pane by 5 columns
        ] ............. enlarges the left pane by 5 columns
        } ............. enlarges the panes vertically by 1 row
        C-} ........... enlarges the panes vertically as much as it can
        C-c } ......... enlarges the panes vertically as much as it can
        { ............. shrinks the panes vertically by 1 row
        C-{ ........... shrinks the panes vertically as much as it can
        C-c { ......... shrinks the panes vertically as much as it can
        \ ............. restores the size of all windows back to «normal»
        C-c C-z ....... enable/disable synchronized navigation

        C-= ........... smart compare files (ediff)
        C-c = ......... smart compare files (console compatible)
        = ............. fast smart compare files (plain diff)
        C-M-= ......... compare panes
        C-x = ......... compare panes (console compatible)

        C-c C-f ....... execute Find-dired in Sunrise VIRTUAL mode
        C-c C-n ....... execute find-Name-dired in Sunrise VIRTUAL mode
        C-c C-g ....... execute find-Grep-dired in Sunrise VIRTUAL mode
        C-u C-c C-g ... execute find-Grep-dired with additional grep options
        C-c C-l ....... execute Locate in Sunrise VIRTUAL mode
        C-c C-r ....... browse list of Recently visited files (requires recentf)
        C-c C-c ....... [after find, locate or recent] dismiss virtual buffer
        C-c / ......... narrow the contents of current pane using fuzzy matching
        C-c b ......... partial Branch view of selected items in current pane
        C-c p ......... Prune paths matching regular expression from current pane
        ; ............. follow file (go to same directory as selected file)
        M-; ........... follow file in passive pane
        C-M-o ......... follow a projection of current directory in passive pane

        C-> ........... save named checkpoint (a.k.a. "bookmark panes")
        C-c > ......... save named checkpoint (console compatible)
        C-.    ........ restore named checkpoint
        C-c .  ........ restore named checkpoint

        C-x C-q ....... put pane in Editable Dired mode (commit with C-c C-c)
        @! ............ fast backup files (not dirs!), each to [filename].bak

        C-c t ......... open new terminal or switch to already open one
        C-c T ......... open terminal AND/OR change directory to current
        C-c C-t ....... open always a new terminal in current directory
        C-c M-t ....... open a new terminal using an alternative shell program
        q, C-x k ...... quit Sunrise Commander, restore previous window setup
        M-q ........... quit Sunrise Commander, don't restore previous windows

******* Additionally, the following traditional commander-style keybindings are provided (these may be disabled by customizing the `sr-use-commander-keys' option):

        F2 ............ go to directory
        F3 ............ quick visit selected file
        F4 ............ visit selected file
        F5 ............ copy marked (or current) files and directories
        F6 ............ rename marked (or current) files and directories
        F7 ............ create new directory
        F8 ............ delete marked (or current) files and directories
        F10 ........... quit Sunrise Commander
        C-F3 .......... sort contents of current pane by name
        C-F4 .......... sort contents of current pane by extension
        C-F5 .......... sort contents of current pane by time
        C-F6 .......... sort contents of current pane by size
        C-F7 .......... sort contents of current pane numerically
        S-F7 .......... soft-link selected file/directory to passive pane
        Insert ........ mark file
        C-PgUp ........ go to parent directory

Any other dired keybinding (not overridden by any of the above) can be used in Sunrise, like G for changing group, M for changing mode and so on.

******* Some more bindings are available in terminals opened using any of the Sunrise functions (i.e. one of: C-c t, C-c T, C-c C-t, C-c M-t):

        C-c Tab ....... switch focus to the active pane
        C-c t ......... cycle through all currently open terminals
        C-c T ......... cd to the directory in the active pane
        C-c C-t ....... open new terminal, cd to directory in the active pane
        C-c ; ......... follow the current directory in the active pane
        C-c { ......... shrink the panes vertically as much as possible
        C-c } ......... enlarge the panes vertically as much as possible
        C-c \ ......... restore the size of all windows back to «normal»
        C-c C-j ....... put terminal in line mode
        C-c C-k ....... put terminal back in char mode

******* The following bindings are available only in line mode (eshell is considered to be *always* in line mode):

        M-<up>, M-P ... move cursor up in the active pane
        M-<down>, M-N . move cursor down in the active pane
        M-Return ...... visit selected file/directory in the active pane
        M-J ........... go to parent directory in the active pane
        M-G ........... refresh active pane
        M-Tab ......... switch to passive pane (without leaving the terminal)
        M-M ........... mark selected file/directory in the active pane
        M-Backspace ... unmark previous file/directory in the active pane
        M-U ........... remove all marks from the active pane
        C-Tab ......... switch focus to the active pane

******* In a terminal in line mode the following substitutions are also performed automatically:

       %f - expands to the currently selected file in the left pane
       %F - expands to the currently selected file in the right pane
       %m - expands to the list of paths of all marked files in the left pane
       %M - expands to the list of paths of all marked files in the right pane
       %n - expands to the list of names of all marked files in the left pane
       %N - expands to the list of names of all marked files in the right pane
       %d - expands to the current directory in the left pane
       %D - expands to the current directory in the right pane
       %a - expands to the list of paths of all marked files in the active pane
       %A - expands to the current directory in the active pane
       %p - expands to the list of paths of all marked files in the passive pane
       %P - expands to the current directory in the passive pane
       %% - inserts a single % sign.

******* In addition to any hooks its parent mode `dired-mode' might have run, this mode runs the hook `sr-mode-hook', as the final step during initialization.

key             binding
---             -------

e .. f		dired-find-file

C-c		Prefix Command
C-e		sr-scroll-up
TAB		sr-change-window
RET		sr-advertised-find-file
C-o		dired-omit-mode
C-q		sr-multi-occur
C-t		Prefix Command
C-x		Prefix Command
C-y		sr-scroll-down
ESC		Prefix Command
SPC		sr-scroll-quick-view
!		dired-do-shell-command
#		dired-flag-auto-save-files
$		dired-hide-subdir
%		Prefix Command
&		dired-do-async-shell-command
*		Prefix Command
+		dired-create-directory
-		negative-argument
.		dired-clean-directory
/		sr-goto-dir
0 .. 9		digit-argument
:		Prefix Command
;		sr-follow-file
<		dired-prev-dirline
=		sr-diff
>		dired-next-dirline
?		sr-summary
@		sr-fast-backup-files
A		sr-do-search
B		dired-do-byte-compile
C		sr-loop-do-copy
D		sr-do-delete
F		sr-do-find-marked-files
G		dired-do-chgrp
H		sr-do-hardlink
I		dired-info
J		sr-dired-prev-subdir
K		sr-loop-do-clone
L		dired-do-load
M		dired-do-chmod
N		dired-man
O		dired-do-chown
P		dired-do-print
Q		sr-do-query-replace-regexp
R		sr-loop-do-rename
S		sr-do-symlink
T		dired-do-touch
U		dired-unmark-all-marks
V		dired-do-run-mail
X		sr-advertised-execute-file
Y		sr-do-relsymlink
Z		dired-do-compress
[		sr-enlarge-right-pane
\		sr-popviewer-setup-windows
]		sr-enlarge-left-pane
^		sr-dired-prev-subdir
a		dired-find-alternate-file
b		sr-browse-file
d		dired-flag-file-deletion
g		revert-buffer
h		sr-describe-mode
i		dired-maybe-insert-subdir
j		sr-goto-dir
k		dired-do-kill-lines
l		dired-do-redisplay
m		dired-mark
n		dired-next-line
o		sr-popviewer-quick-view
p		dired-previous-line
q		sr-quit
r		sr-reverse-pane
s		sr-interactive-sort
t		dired-toggle-marks
u		dired-unmark
v		sr-popviewer-quick-view
w		dired-copy-filename-as-kill
x		sr-do-flagged-delete
y		sr-show-files-info
{		sr-shrink-panes
}		sr-enlarge-panes
~		dired-flag-backup-files
DEL		dired-unmark-backward
S-SPC		sr-scroll-quick-view-down
C-.		sr-checkpoint-restore
C-=		sr-ediff
C->		sr-checkpoint-save
C-{		sr-min-lock-panes
C-}		sr-max-lock-panes
<A-down>	sr-next-line-other
<A-up>		sr-prev-line-other
<C-backspace>	sr-toggle-attributes
<C-f3>		sr-sort-by-name
<C-f4>		sr-sort-by-extension
<C-f5>		sr-sort-by-time
<C-f6>		sr-sort-by-size
<C-f7>		sr-sort-by-number
<C-prior>	sr-dired-prev-subdir
<C-tab>		sr-popviewer-select-viewer-window
<M-S-down>	sr-tree-view
<M-S-down-mouse-1>		sr-tree-mouse-view
<M-down>	sr-next-line-other
<M-up>		sr-prev-line-other
<S-f7>		sr-do-symlink
<backspace>	dired-unmark-backward
<f10>		sr-quit
<follow-link>	mouse-face
<insert>	sr-mark-toggle
<mouse-2>	sr-mouse-change-window
<remap>		Prefix Command

C-t RET		sr-tree-view
C-t SPC		sr-tree-view

<remap> <undo>	sr-undo
<remap> <undo-only>		sr-undo

C-x C-f		sr-find-file
C-x C-q		sr-editable-pane
C-x =		sr-compare-panes
C-x k		sr-kill-pane-buffer
  (that binding is currently shadowed by another mode)

C-c C-b		sr-mirror-toggle
C-c C-c		revert-buffer
C-c C-d		sr-recent-directories
C-c C-f		sr-find
C-c C-g		sr-find-grep
C-c TAB		sr-popviewer-select-viewer-window
C-c C-l		sr-locate
C-c RET		sr-advertised-find-file-other
C-c C-n		sr-find-name
C-c C-r		sr-recent-files
C-c C-s		sr-split-toggle
C-c C-t		sr-term-cd-newterm
C-c C-v		sr-pure-virtual
C-c C-w		sr-browse-pane
C-c C-z		sr-sync
C-c ESC		Prefix Command
C-c .		sr-checkpoint-restore
C-c /		sr-fuzzy-narrow
C-c ;		sr-follow-viewer
C-c =		sr-ediff
C-c >		sr-checkpoint-save
C-c T		sr-term-cd
C-c b		sr-flatten-branch
C-c p		sr-prune-paths
C-c r		sr-sticky-isearch-backward
C-c s		sr-sticky-isearch-forward
C-c t		sr-term
C-c v		sr-virtualize-pane
C-c {		sr-min-lock-panes
C-c }		sr-max-lock-panes
C-c DEL		sr-toggle-attributes

M-RET		sr-advertised-find-file-other
C-M-o		sr-project-path
C-M-u		sr-history-next-other
C-M-y		sr-history-prev-other
M-SPC		sr-scroll-quick-view-down
M-+		sr-create-files
M-;		sr-follow-file-other
M-C		dired-do-copy
M-D		dired-do-delete
M-H		dired-do-hardlink
M-J		sr-prev-subdir-other
M-M		sr-unmark-backward-other
M-R		dired-do-rename
M-S		dired-do-symlink
M-U		sr-unmark-all-marks-other
M-Y		dired-do-relsymlink
M-^		sr-prev-subdir-other
M-a		sr-beginning-of-buffer
M-e		sr-end-of-buffer
M-f		sr-advertised-find-file-other
M-j		sr-goto-dir-other
M-l		sr-toggle-truncate-lines
M-m		sr-mark-other
M-n		sr-next-line-other
M-o		sr-synchronize-panes
M-p		sr-prev-line-other
M-q		sunrise-cd
M-t		sr-transpose-panes
M-u		sr-history-next
M-y		sr-history-prev
C-M-=		sr-compare-panes
ESC <down>	sr-tree-view

C-t C-t		image-dired-dired-toggle-marked-thumbs
C-t .		image-dired-display-thumb
C-t a		image-dired-display-thumbs-append
C-t c		image-dired-dired-comment-files
C-t d		image-dired-display-thumbs
C-t e		image-dired-dired-edit-comment-and-tags
C-t f		image-dired-mark-tagged-files
C-t i		image-dired-dired-display-image
C-t j		image-dired-jump-thumbnail-buffer
C-t r		image-dired-delete-tag
C-t t		image-dired-tag-files
C-t x		image-dired-dired-display-external

C-M-d		dired-tree-down
C-M-n		dired-next-subdir
  (that binding is currently shadowed by another mode)
C-M-p		dired-prev-subdir
  (that binding is currently shadowed by another mode)
C-M-u		dired-tree-up
  (that binding is currently shadowed by another mode)
M-!		dired-smart-shell-command
M-$		dired-hide-all
M-(		dired-mark-sexp
M-G		dired-goto-subdir
M-o		dired-omit-mode
  (that binding is currently shadowed by another mode)
M-s		Prefix Command
M-{		dired-prev-marked-file
M-}		dired-next-marked-file
M-DEL		dired-unmark-all-files

M-s a		Prefix Command
M-s f		Prefix Command

% &		dired-flag-garbage-files
% C		dired-do-copy-regexp
% H		dired-do-hardlink-regexp
% R		dired-do-rename-regexp
% S		dired-do-symlink-regexp
% Y		dired-do-relsymlink-regexp
% d		dired-flag-files-regexp
% g		dired-mark-files-containing-regexp
% l		dired-downcase
% m		dired-mark-files-regexp
% r		dired-do-rename-regexp
% u		dired-upcase

 C-n		dired-next-marked-file
 C-p		dired-prev-marked-file
 !		dired-unmark-all-marks
 %		dired-mark-files-regexp
 (		dired-mark-sexp
 *		dired-mark-executables
 .		dired-mark-extension
 /		dired-mark-directories
 ?		dired-unmark-all-files
 @		dired-mark-symlinks
 O		dired-mark-omitted
 c		dired-change-marks
 m		dired-mark
 s		dired-mark-subdir-files
 t		dired-toggle-marks
 u		dired-unmark
DEL		dired-unmark-backward

: d		epa-dired-do-decrypt
: e		epa-dired-do-encrypt
: s		epa-dired-do-sign
: v		epa-dired-do-verify

<remap> <advertised-undo>	dired-undo
<remap> <next-line>		dired-next-line
<remap> <previous-line>		dired-previous-line
<remap> <read-only-mode>	dired-toggle-read-only
<remap> <toggle-read-only>	dired-toggle-read-only
<remap> <undo>			dired-undo
  (that binding is currently shadowed by another mode)

C-c M-t		sr-term-cd-program

M-s f C-s	dired-isearch-filenames
M-s f ESC	Prefix Command

M-s a C-s	dired-do-isearch
M-s a ESC	Prefix Command

M-s f C-M-s	dired-isearch-filenames-regexp

M-s a C-M-s	dired-do-isearch-regexp
****** name spaces
******* F8 F8 Name Space: (minor|sub)Modes
******** f8 f8 f4: shell in active dir
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> <f8> <f4>") 'sr-term-cd)
#+END_SRC

******** f8 f8 f7: sr-speedbar-toggle
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> <f8> <f7>") 'sr-speedbar-toggle)
#+END_SRC
******** 0 f8 f8 f8: run deft in current directory
#+BEGIN_SRC emacs-lisp

;(defun zmy-deft ()
 ; "Run deft in directory dir"
;  (interactive "sEnter dir: ")
  ;(kill-buffer-and-its-windows "*Deft*")

  ;(setq deft-directory ".") (deft) (switch-to-buffer "*Deft*"))


;(global-set-key (kbd "<f8> <f8> <f8>") 'zmy-deft)

#+END_SRC
******** 0 f8 f8 f8 p: run deft in pendrive
#+BEGIN_SRC emacs-lisp
;(global-set-key (kbd "<f8> <f8> <f8> p") (zmy-deft "/mnt/sdb1/home/data/current/org/"))

#+END_SRC
******** f8 f8 f9: sunrise-cd
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> <f8> <f9>") 'sunrise-cd)
#+END_SRC
******** f8 f8 left: sr-tree-mode
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> <f8> <left>") 'sr-tree-mode)
#+END_SRC
****** direct
******* f8 up: up dir
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> <up>") 'sr-dired-prev-subdir)
#+END_SRC
******* f8 del: sr-delete = sr-do-delete
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> <delete>") 'sr-do-delete)
#+END_SRC

******* f8 f5: sr-copy = sr-loop-do-copy
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> <f5>") 'sr-loop-do-copy)
#+END_SRC

******* f8 f6: move = sr-loop-do-rename
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> <f6>") 'sr-loop-do-rename)
#+END_SRC
******* f8 f7: create dir = sr-tree-create-directory
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> <f7>") 'sr-tree-create-directory)
#+END_SRC
******* f8 d: dired Downloads dir
#+BEGIN_SRC emacs-lisp
(defun zdired-writer ()
  (interactive)
  (dired "/mnt/sda9/Downloads/"))

(global-set-key (kbd "<f8> d") 'zdired-writer)

#+END_SRC

******* f8 f: find-file
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> f") 'find-file)
#+END_SRC

******* f8 r: recentf-open-files
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> r") 'recentf-open-files)
(recentf-mode)
#+END_SRC

******* f8 j: bookmark+: jump
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> j") 'bookmark-jump)
#+END_SRC

******* f8 l: bookmark+: list/edit
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> l") 'bookmark-bmenu-list)
#+END_SRC

******* f8 m: bookmark+: mark
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> m") 'bmkp-bookmark-set-confirm-overwrite)
#+END_SRC

******* f8 t: bookmark+: tag a file
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> t") 'bmkp-tag-a-file)
#+END_SRC

******* f8 w: webjump
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "<f8> w") 'webjump)
#+END_SRC
***** f10
#+BEGIN_SRC emacs-lisp
  (global-set-key [(f10)(f10)] 'menu-bar-open)
#+END_SRC
***** f11
#+BEGIN_SRC emacs-lisp
  (global-set-key [(f11)(f11)] 'toggle-frame-fullscreen)
#+END_SRC
*** markdown
#+BEGIN_SRC emacs-lisp
  (use-package markdown-mode
  :ensure t)
#+END_SRC
*** org
**** UI
****** Customize newlines
#+begin_src emacs-lisp
(customize-set-variable 'org-blank-before-new-entry
                        '((heading . nil)
                          (plain-list-item . nil)))
(setq org-cycle-separator-lines 1)
#+end_src
****** Hide markers
#+BEGIN_SRC emacs-lisp
(setq org-hide-emphasis-markers t)
#+END_SRC
****** hide-leading-stars
#+BEGIN_SRC emacs-lisp
  (setq org-hide-leading-stars 't)
#+END_SRC
****** Indent
#+BEGIN_SRC emacs-lisp
  (setq org-indent-indentation-per-level 1)
  (setq org-startup-indented t)
#+END_SRC

****** Display images
#+BEGIN_SRC emacs-lisp
(setq org-startup-with-inline-images t)
(add-hook
 'org-babel-after-execute-hook
 (lambda ()
   (when org-inline-image-overlays
     (org-redisplay-inline-images))))
#+END_SRC
****** Enable auto-fill mode
#+BEGIN_SRC emacs-lisp
(add-hook
 'org-mode-hook
 (lambda ()
   (auto-fill-mode)))
#+END_SRC
**** standard-key-bindings
#+BEGIN_SRC emacs-lisp

  (global-set-key "\C-cl" 'org-store-link)
  (global-set-key "\C-ca" 'org-agenda)
  (global-set-key "\C-cb" 'org-iswitchb)

  (setq org-log-done t
        org-todo-keywords '((sequence "t" "o"))
        org-todo-keyword-faces '(("t" . (:foreground "black" :background "dark red" :weight bold))
                                 ("o" . (:foreground "black" :background "dark green" :weight bold))))

  #+END_SRC
**** file-types-to-open
#+BEGIN_SRC emacs-lisp
(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
#+END_SRC
**** showing-source-block-syntax-highlighting
#+BEGIN_SRC emacs-lisp
(setq org-src-fontify-natively t)
#+END_SRC
**** load-languages
***** Picolisp in Org Babel
****** From https://github.com/tj64/ob-picolisp

It used to ship with a picolisp-mode and an inferior-picolisp-mode
for Emacs (to be found in the /lib/el/ directory) until Pil64, but
from Pil21 on these libraries have to be found on GitHub
(e.g. https://github.com/tj64). The same holds for former library
files for line editing (led.l and eled.l, replaced by readline lib
in Pil21) and for symbol editing (edit.l and eedit.l, replaced by
the use of VIP, the editor written in and shipped with Pil21).

There are two Emacs modes now, picolisp-mode (older, more official)
and plist-mode (newer, less tested). Both rely on the same
inferior-picolisp.el file.
****** copy ob-picolisp.el from https://github.com/tj64/ob-picolisp to .emacs.d/.
***** org-babel-do-load-languages
#+BEGIN_SRC emacs-lisp

(org-babel-do-load-languages 'org-babel-load-languages
  '((ditaa . t)
   (dot . t)
   (emacs-lisp . t)
   (gnuplot . t)
;   (guile . t)
   (ruby . t)
   (latex . t)
   (ledger . t)
   (lisp . t)
   (picolisp . t)
;   (python . t)
   (R . t)
   (scheme . t)
   (shell . t)))

#+END_SRC
**** org-confirm-babel-evaluate
#+BEGIN_SRC emacs-lisp
  (setq org-confirm-babel-evaluate  nil)
#+END_SRC
**** org-contrib
#+BEGIN_SRC emacs-lisp
; https://chrismaiorana.com/org-contrib/
  (use-package org-contrib
    :ensure t)
  (require 'ox-extra) ;; the package I wanted to include in my config
  ;; and a function to activate the features of this package:
  (ox-extras-activate '(latex-header-blocks ignore-headlines))
#+END_SRC
**** valign: INSTALL BY HAND
#+BEGIN_SRC emacs-lisp
; https://github.com/casouri/valign
; M-x package-install RET valign RET

(add-hook 'org-mode-hook #'valign-mode)
#+END_SRC
**** htmlize: To export source blocks :: INSTALL BY HAND
To obtain htmlize.el, the standard approach is to use Emacs' built-in package manager, package.el. You can install it using M-x package-install RET htmlize RET.
*** gt                   :tangle-when-needed:
Translator on Emacs. Support multiple engines such as Google, Bing,
deepL, StarDict and Youdao, also support LLMs like ChatGPT, DeepSeek
and so on.

#+BEGIN_SRC emacs-lisp :tangle no
      ; https://github.com/lorniu/gt.el
        (use-package gt :ensure t)


  ;; Basic configuration:
  ;; Initialize the default translator, let it translate between en and fr via Google Translate,
  ;; and the result will be displayed in the Echo Area.
    (setq gt-langs '(en sa))
    (setq gt-default-translator (gt-translator :engines (gt-google-engine)))



  (setq gt-preset-translators
      `((ts-1 . ,(gt-translator
                  :taker (gt-taker :langs '(en sa) :text 'word)
                  :engines (gt-bing-engine)
                  :render (gt-overlay-render)))
        (ts-2 . ,(gt-translator
                  :taker (gt-taker :langs '(en sa hi) :text 'sentence)
                  :engines (gt-google-engine)
                  :render (gt-insert-render)))
        (ts-3 . ,(gt-translator
                  :taker (gt-taker :langs '(en hi) :text 'buffer
                                   :pick 'word :pick-pred (lambda (w) (length> w 6)))
                  :engines (gt-google-engine)
                  :render (gt-overlay-render :type 'help-echo)))))

#+END_SRC
*** deft
#+BEGIN_SRC emacs-lisp
    ; https://jblevins.org/projects/deft/

  (use-package deft
  :ensure t
  :custom
  (deft-extensions '("org" "md" "txt"))
  (deft-directory "~/org")
  (deft-use-filename-as-title t))

#+END_SRC
*** startup
#+BEGIN_SRC emacs-lisp
  (dired "~/org")

  (deft)
    (switch-to-buffer "*Deft*")
#+END_SRC

*** COMMENT editing text
#+BEGIN_SRC emacs-lisp :tangle no
  ;; delete trailing whitespace
  (add-hook 'before-save-hook #'delete-trailing-whitespace)

  ;; allow overwriting of selected text
  (require 'delsel)
  (delete-selection-mode 1)


#+END_SRC
*** COMMENT open-all-recent-files
#+BEGIN_SRC emacs-lisp
    (defun open-all-recent-files ()
      "Open all recent files."
      (interactive)
      (dolist (file  recentf-list) (find-file file)))
    (open-all-recent-files)
#+END_SRC

* COMMENT
** template
:properties:
:header-args: :tangle no
:end:
#+BEGIN_SRC emacs-lisp
#+END_SRC

#+BEGIN_SRC emacs-lisp
#+END_SRC

#+BEGIN_SRC emacs-lisp
#+END_SRC
