Today's post has some functions from the functions declaration section of the beginning of my initialization file.

  • SET UP, DEFAULTS, AND CUSTOMIZATION
    • Necessary Adjustments when you set-up on a new computer
    • Paths to Update on Change
    • Executable Paths
    • Libraries
    • Function declarations
    • Emacs Customization Seperate File
    • Emax Defaults
    • Some Defaults
    • Frames, Buffers, And Lines
    • Some Custom Default Functions
    • Some New Key Bindings
    • Popup, Pos-tip,Tooltip, Posframe
    • Which Key

There are a lot of function declarations in this initialization file. Most of them are not written by me, but many are edited. Only some of them are here. The main idea with function declarations is to defer them on start-up to save time. One way to do that is to put them in the :config section of a use-package declaration and defer that configuration via one of use-package's defer statements (like :command or :defer). I've yet to defer a lot of things in my initialization. I'll get to it at some point but it's not now in terms of time a priority. Keep that in mind if you use any of these functions in your init file.

Clear The Kill Ring

Pretty straight forward. Emacs keeps lots of goodies you copied on the clipboard. Later I'll show you how you can cycle through them. This bad boy clears everything when you no longer want to deal with the insanity.



;clear kill-ring
(defun clear-kill-ring ()
  "Clear the kill ring variable"
  (interactive)
  (setq kill-ring nil
        kill-ring-yank-pointer nil))

toggle-all-the-icons-dired-mode

You need All The Icons installed for this. See the link for images. All The Icons can be slow with large directories on windows, based on how well your system is optimized for memory. This let's you use it when you want to (for example when transferring files between directories or cleaning them up).




;toggle-all-the-icons-dired-mode
(defun toggle-all-the-icons-dired-mode ()
(interactive)
(if (featurep 'all-the-icons-dired)
(if all-the-icons-dired-mode
(progn
(setq all-the-icons-dired-mode nil)
(remove-hook 'dired-mode-hook 'all-the-icons-dired-mode ));end on case
(progn
(all-the-icons-dired-mode)
(add-hook 'dired-mode-hook 'all-the-icons-dired-mode ));end off case
);end conditional
);end package conditional
);end toggle-all-the-icons

Shell get buffer create

This is used by the function that follows it, "shell-same-window". It opens a shell in the buffer you are working in.



;shell in same window
(defun shell-get-buffer-create (&optional buffer)
  "Run an inferior shell, with I/O through BUFFER (which defaults to `*shell*').
Interactively, a prefix arg means to prompt for BUFFER.
If `default-directory' is a remote file name, it is also prompted
to change if called with a prefix arg.
If BUFFER exists but shell process is not running, make new shell.
If BUFFER exists and shell process is running, just switch to BUFFER.
Program used comes from variable `explicit-shell-file-name',
 or (if that is nil) from the ESHELL environment variable,
 or (if that is nil) from `shell-file-name'.
If a file `~/.emacs_SHELLNAME' exists, or `~/.emacs.d/init_SHELLNAME.sh',
it is given as initial input (but this may be lost, due to a timing
error, if the shell discards input when it starts up).
The buffer is put in Shell mode, giving commands for sending input
and controlling the subjobs of the shell.  See `shell-mode'.
See also the variable `shell-prompt-pattern'.
To specify a coding system for converting non-ASCII characters
in the input and output to the shell, use \\[universal-coding-system-argument]
before \\[shell].  You can also specify this with \\[set-buffer-process-coding-system]
in the shell buffer, after you start the shell.
The default comes from `process-coding-system-alist' and
`default-process-coding-system'.
The shell file name (sans directories) is used to make a symbol name
such as `explicit-csh-args'.  If that symbol is a variable,
its value is used as a list of arguments when invoking the shell.
Otherwise, one argument `-i' is passed to the shell.
\(Type \\[describe-mode] in the shell buffer for a list of commands.)"
  (interactive
   (list
    (and current-prefix-arg
   (prog1
       (read-buffer "Shell buffer: "
        ;; If the current buffer is an inactive
        ;; shell buffer, use it as the default.
        (if (and (eq major-mode 'shell-mode)
           (null (get-buffer-process (current-buffer))))
            (buffer-name)
          (generate-new-buffer-name "*shell*")))
     (if (file-remote-p default-directory)
         ;; It must be possible to declare a local default-directory.
               ;; FIXME: This can't be right: it changes the default-directory
               ;; of the current-buffer rather than of the *shell* buffer.
         (setq default-directory
         (expand-file-name
          (read-directory-name
           "Default directory: " default-directory default-directory
           t nil))))))))
  (setq buffer (if (or buffer (not (derived-mode-p 'shell-mode))
                       (comint-check-proc (current-buffer)))
                   (get-buffer-create (or buffer "*shell*"))
                 ;; If the current buffer is a dead shell buffer, use it.
                 (current-buffer)))
;; On remote hosts, the local `shell-file-name' might be useless.
  (if (and (called-interactively-p 'any)
     (file-remote-p default-directory)
     (null explicit-shell-file-name)
     (null (getenv "ESHELL")))
      (with-current-buffer buffer
  (set (make-local-variable 'explicit-shell-file-name)
       (file-remote-p
        (expand-file-name
         (read-file-name
    "Remote shell path: " default-directory shell-file-name
    t shell-file-name))
        'localname))))
;; The buffer's window must be correctly set when we call comint (so
  ;; that comint sets the COLUMNS env var properly).
  (with-current-buffer buffer
    (unless (comint-check-proc buffer)
      (let* ((prog (or explicit-shell-file-name
           (getenv "ESHELL") shell-file-name))
       (name (file-name-nondirectory prog))
       (startfile (concat "~/.emacs_" name))
       (xargs-name (intern-soft (concat "explicit-" name "-args"))))
        (unless (file-exists-p startfile)
    (setq startfile (concat user-emacs-directory "init_" name ".sh")))
        (apply 'make-comint-in-buffer "shell" buffer prog
         (if (file-exists-p startfile) startfile)
         (if (and xargs-name (boundp xargs-name))
       (symbol-value xargs-name)
           '("-i")))
        (shell-mode))))
  buffer)

Open Shell In Same Window

Opens a shell in the window you are working.



;open shell in same window
(defun shell-same-window ()
(interactive)
(switch-to-buffer (shell-get-buffer-create))
);shell-same-window

Here are couple of mpd player functions.

The mpd player is the music player I use. You can stream music with it also. It's a command line tool you can read about here. MPD needs to be stopped and started from the shell. So there are a couple of windows scripts here that do that.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18

(defun launch-mpd ()
(interactive)
(w32-shell-execute nil mpd-start-p nil)
);end launch mpd
(defun stop-mpd ()
(interactive)
(w32-shell-execute nil mpd-stop-p nil)
);end stop mpd
;mpd toggle
;(defvar mpd-on 0)
(setq mpd-on 0)
(defun toggle-mpd-player ()
"Turns on mpd via win com file and winvbs file in mpd-start path if mpd-on = nil. Turns off mpd by win com in mpd-stop path if mpd-on = 1. If mpd started by another process when mpd-on = nil, this function won't work."
(interactive)
(if (= mpd-on 0)(progn(launch-mpd)(setq mpd-on 1)(mingus-help)(get-buffer "*Mingus Help*"))
(progn (mingus-stop)(stop-mpd)(setq mpd-on 0)(kill-buffer (get-buffer "*Mingus Help*"))
(kill-buffer (get-buffer "*Mingus*"))(kill-buffer (get-buffer "*Mingus Browser*")))));end toggle-mpd

And here are the script paths and scripts. VBS scripts can run without opening a shell window on the desktop, so those scripts reference the windows shell-scripts, which is one way to do it.


1
2
3

(defvar mpd-start-p "...path-to...mpd-windows-master/start-silently-mpd.vbs")
(defvar mpd-stop-p "...path-to...mpd-windows-master/stop-mpd-silently.vbs")

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19

; start vbs file
'HideBat.vbs
CreateObject("Wscript.Shell").Run "...path-to.../mpd-windows-master/start.bat", 0, True

; stop vbs file
'HideBat.vbs
CreateObject("Wscript.Shell").Run "...path-to.../mpd-windows-master/stop-mpd.cmd", 0, True

;start.bat
ECHO OFF

for /f %%i in ("%0") do set curpath=%%~dpi
cd /d %curpath%

mpd.exe --no-daemon -v --stdout mpd.conf

;stop-mdp.cmd
TASKKILL /IM "mpd.exe" /F

MPD player needs an emacs compatible interface and I use the Mingus Player for that. I'll post later the hydra I use to interface the mingus player functions. '

The rest of the functions in this init section support the Windows Program Launcher. Here's some code for that hydra.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

(defvar program-launcher-title (with-octicon "device-desktop" "Windows Program Launcher"))
;generate hydra
(pretty-hydra-define Windows-Exe (:title program-launcher-title :quit-key "q" :color blue )
("A"
(
    ("w" launch-word "Launch Word")
    ("e" launch-excel "Launch Excel")
    ("7" launch-7z "Launch 7zip")
    ("p" launch-powershell "Launch Powershell" )
    ("c" launch-cmd "Launch Command Prompt")
    ("U" launch-ubuntu1804 "Launch Ubuntu")
    ("u" launch-ubuntu1804-win-p "Launch Ubuntu Mount")
);end A
"B"
(
    ("g" launch-gimp "Launch Gimp" )
    ("i" launch-inkscape "Launch Inkscape" )
    ("f" launch-fsviewer "Launch FSViewer" )
    ( "@" launch-paint "Launch Paint")
    ("m" launch-mpd "Launch MPD Music Player" )
    ("o" launch-onedrive "Launch Onedrive" )
    ("k" launch-keycast "Launch Keycast" )

);end B

"C"
(
     ("x" launch-xampp "Launch Xampp")
     ("l" launch-live-reload "Launch Live Reload")
     ("n" launch-notepad++ "Launch Notepad++")
     ("d" launch-dropbox "Launch Dropbox")
     ("a" launch-atom "Launch Atom Editor")
     ("s" launch-screen-cast "Launch Screen Cast Viewer" )
     ("+" launch-win-calc "Launch Calculator")
     ("h" hydra-helm/body "Return To Helm" :color blue )
     ("<SPC>" nil "Quit" :color blue)
);end C
);end hydra body
);end pretty-hydra-appearance
(bind-key "<C-m> x" 'Windows-Exe/body)

So that's all for this section. Next are defaults and customizations. If you already have an emacs init you should be familiar with many of the upcoming defaults.


That’s all for now…