guide.md 6.5 KB

Useful stuff

Process explorer

M-x proced RET

eshell -> clipboard

command > /dev/clip

run visual commands in eshell

some are already defined as visual, other are not, in which case you might want to add them:

(add-to-list 'eshell-visual-commands "htop")

for example

eshell pipe support

command | command
command >>> #<buffer name>
command > filename

all the shells

  • shell - bash / sh in Emacs
  • eshell - eshell
  • ielm - elisp REPL
  • term
  • ansi-term

modify eshell prompt

(defun set-eshell-prompt-function ()
  (setq eshell-prompt-function
        (function
         (lambda ()
           (concat
            (propertize (format-time-string "%H:%M:%S" (current-time))
                        'face
                        `(:foreground "#A0A0A0"))
            "::"
            (propertize (user-login-name)
                        'face
                        `(:foreground "#FF9080"))
            "@"
            (propertize (let ((sys-name (system-name)))
                          (let ((sys-name-len (length sys-name)))
                            (if (> sys-name-len 8)
                                (concat (substring sys-name 0 8) "...")
                              sys-name)))
                        'face
                        `(:foreground "#FF9080"))
            "::"
            (propertize
             (let ((limit 36)
                   (loc
                    (if (string= (eshell/pwd) (getenv "HOME"))
                        "~"
                      (eshell/pwd))))
               (let ((loc-length (length loc)))
                 (if (> loc-length limit)
                     (concat "..." (substring loc (- loc-length limit)))
                   loc)))
             'face
             `(:foreground "#FF9080"))
            "$ "))))
  (setq eshell-highlight-prompt t)
  (setq eshell-prompt-regexp "^[^#$\n]*[#$] "))

(set-eshell-prompt-function)

inspect buffer variables

M-x pp-eval-expression RET (buffer-local-variables) RET

inspect editorconfig variables

M-x pp-eval-expression RET editorconfig-properties-hash RET

inspect variables

C-h v enter variable name RET

inspect defined procedures

  • C-h f for getting help about procedures
  • enter a procedure name
  • RET

clear eshell

run clear 1

font / face at point

C-u C-x =

or

M-x describe-face RET

Library of Babel

Library of Babel (LoB) allows you to define a function in any supported programming language and use it inside org documents. The following contains examples for usage of the LoB. (If you are viewing this document's markdown version, the following examples probably will not be completely visible, as there are org-mode elements, which have no equivalent in typical markdown dialects.)

Ingest org files

In order to use functions defined in source blocks within other files, one needs to "ingest" them first, using either M-x org-babel-lob-ingest or default key binding C-c C-v i.

Guile version

(version)
3.0.7

Upcase string

(define upcase
  (λ (str)
    (string-upcase str)))

(upcase input-str)
TEST

Timestamp calculation example

(import
 (ice-9 format)
 (srfi srfi-19))


(define org-timestamp->time-utc
  (λ (timestamp-string)
    (let ([parsed-date (string->date timestamp-string "[~Y-~m-~d ~a ~H:~M]")])
          (date->time-utc parsed-date))))


(define duration->hours
  (λ (duration)
    ;; 1h = 60min = 3600s
    (/ (time-second duration) 3600)))


(define org-lob-timediff
  (λ (org-dt1 org-dt2)
    ;; formatting float:

    ;; ~@width, decimals, scale, overflowchar, padchar

    ;; ~ placeholder is following
    ;; @ with sign if negative
    ;; width: minimum width
    ;; decimals: minimum number of digits after decimal point
    ;; scale: ???
    ;; overflowchar: ???
    ;; padchar: char to use for padding
    (format #f
            "~,2f"
            (number->string
             (exact->inexact
              (duration->hours
               (time-difference (org-timestamp->time-utc org-dt2)
                                (org-timestamp->time-utc org-dt1))))))))


(org-lob-timediff dt1 dt2)

Finding help inside Emacs

Key bindings

Usually you can use C-h k for "help about key". Emacs will then query for the key combination, which you want help for. Sometimes however the key combination is bound by the system's window manager for example and this will prevent Emacs to receive your key combination, which means you cannot answer its query with that key combination. In such cases you can use the following way of getting help:

(describe-key (kbd "M-TAB"))

Font stuff

set default font

Put the following in your init.el file:

(let ((standard-font "DejaVu Sans Mono:weight=normal:height=110:antialias=1"))
  (set-frame-font standard-font))

set charset or fontset font

This is useful when wanting to use a different font for characters of other languages, which might require a different font, like Chinese.

Put the following in your init.el file:

;; A fontset font seems to be a font, which is used for a specific set of
;; characters, which can be associated with a particular language. Using fontset
;; font settings, it should be possible to set a font per langugage, as is
;; probably done on the Emacs HELLO page.

(let ((chinese-font "WenQuanYi Micro Hei Mono:weight=normal:height=140:antialias=1"))
  (dolist (charset '(kana han symbol cjk-misc bopomofo))
    (set-fontset-font "fontset-default"
                      charset
                      chinese-font)))