...das minhas cousas

 


Recompile all .el files in directory

(byte-recompile-directory ".emacs.d/var/lisp/" 0 t)

Add shell variable from shell

# the variable
MY-VARIABLE="SOME VALUE"
# add to Emacs environment variables, 'process-environment'
emacsclient -e "(setenv \"MY-VARIABLE\" \"$MY-VARIABLE\")"

Get exit status from asynchronous shell command

(defun run-command-and-get-exit-status (label output-buffer command-string)
  (let ((proc (start-process-shell-command label output-buffer command-string))
        command-exit-status)
    (set-process-sentinel proc (lambda (_ __)
                                 (when (eq 'exit (process-status proc))
                                   (setq command-exit-status (process-exit-status proc))
                                   (throw 'exit nil))))
    (recursive-edit)
    command-exit-status))

Check Emacs Lisp code style

Check it Help me!
M-x checkdoc M-: (info “(elisp) Tips”)

Quick Calc

A quick operation Help me!
C-x * d 3+4/2+4! M-x calc-dispatch-help

Compile and run

(defun compilation-run-command-maybe (buffer desc)
  "Launch compiled binary if compilation exit with success status."
  (when (string= desc "finished\n")
    (let* ((splited (split-string compile-command))
           (cmd (car splited))
           (binary (pcase cmd
                     ((or "gcc" "g++")
                      (nth (1+ (seq-position splited "-o")) splited))
                     (code ""))))
      (when (not (string= binary ""))
        (term (concat (file-name-as-directory compilation-directory)
                      binary))))))

(add-hook 'compilation-finish-functions #'compilation-run-command-maybe)

Perspective switching back-and-forth

(defun pedro-persp-switch ()
  "Does not take care if persp keybinding is not control+digit!!!.
Does not take care if current persp name is not a string number!!!.
The constant 67108912 if for 'C-0'."
  (interactive)
  (let* ((control-zero-keyseq-value 67108912)

         (new-persp-name (number-to-string
                          (- (elt (this-command-keys-vector) 0)
                             control-zero-keyseq-value)))
         (current-persp-name (persp-current-name)))

    (if (string= current-persp-name new-persp-name)
        (persp-switch-last)
      (persp-switch new-persp-name))))

Silence logging in Messages buffer

help-gnu-emacs.gnu.org list: Re: silence append-to-file?

  • set message-log-max variable to nil
(let (message-log-max)
  (message ...))

Don’t let messages appear in the mini-buffer

help-gnu-emacs.gnu.org list: RE: [External] : messages to Messages without appearing in mini-buffer?

  • set inhibit-message variable to nil
(let ((inhibit-message  t))
  (message "Msg only to be logged in *Messages*"))

TODO open-dribble-file function

TODO which-key-dump-bindings

TODO pkill -SIGUSR2 emacs

TODO “Save a screenshot of the current frame as an SVG image.”

https://libredd.it/r/emacs/comments/idz35e/emacs_27_can_take_svg_screenshots_of_itself/

(defun screenshot-svg ()
  "Save a screenshot of the current frame as an SVG image.
Saves to a temp file and puts the filename in the kill ring."
  (interactive)
  (let* ((filename (make-temp-file "Emacs" nil ".svg"))
         (data (x-export-frames nil 'svg)))
    (with-temp-file filename
      (insert data))
    (kill-new filename)
    (message filename)))