Skip to content

Latest commit

 

History

History
727 lines (655 loc) · 21.5 KB

android.org

File metadata and controls

727 lines (655 loc) · 21.5 KB

Essentials

Sometimes there is a error on Emacs startup, so this following configs will enable to debug with some comfort.

(load-theme 'misterioso)

Key mapping

Buffer/Window

Before kill a modified buffer, give option to see the diff Original code from here

(defun my/kill-this-buffer ()
  (interactive)
  (catch 'quit
    (save-window-excursion
      (let (done)
        (when (and buffer-file-name (buffer-modified-p))
          (while (not done)
            (let ((response (read-char-choice
                             (format "Save file %s? (y, n, d, q) " (buffer-file-name))
                             '(?y ?n ?d ?q))))
              (setq done (cond
                          ((eq response ?q) (throw 'quit nil))
                          ((eq response ?y) (save-buffer) t)
                          ((eq response ?n) (set-buffer-modified-p nil) t)
                          ((eq response ?d) (diff-buffer-with-file) nil))))))
        (kill-buffer (current-buffer))))))

(global-set-key [s-tab] 'next-buffer)
(global-set-key [S-s-iso-lefttab] 'previous-buffer)
(global-set-key ["M-{"] 'next-buffer)
(global-set-key ["M-}"] 'previous-buffer)


;; change window
(global-set-key [(C-tab)] 'other-window)
(global-set-key [(C-M-tab)] 'other-window)

;; Remap kill buffer to my/kill-this-buffer
(global-set-key (kbd "C-x k") 'my/kill-this-buffer)

;; Revert buffer
(global-set-key (kbd "C-<f5>") 'revert-buffer)

;; Go to scratch buffer
(global-set-key (kbd "<f2>") (lambda() (interactive)(switch-to-buffer "*scratch*")))

Code navigation

(global-set-key (kbd "M-g") 'goto-line)
(global-set-key (kbd "C-c s") 'sort-lines)

Editing

(global-set-key (kbd "C-c c") 'comment-region)
(global-set-key (kbd "C-c d") 'uncomment-region)

Conf

(global-set-key (kbd "<f6>") (lambda() (interactive)(find-file "~/.emacs.d/readme.org")))

Package manager

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)

;; Bootstrap `use-package'
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

General

;; Close all dired buffers after opening
(setq dired-kill-when-opening-new-dired-buffer t)

(defun dont-kill-scratch ()
  "This function doesn't let you kill scratch by mistake."
  (if (not (equal (buffer-name) "*scratch*"))
      t
    (bury-buffer)
    nil))
(add-hook 'kill-buffer-query-functions #'dont-kill-scratch)
;; Don't ask about variables and functions from .dir-locals
(advice-add 'risky-local-variable-p :override #'ignore)

(use-package ls-lisp
  :config
  (setq ls-lisp-dirs-first t
        ls-lisp-use-insert-directory-program nil))

Startup Performance

Make startup faster by reducing the frequency of garbage collection and then use a hook to measure Emacs startup time.

;; The default is 800 kilobytes.  Measured in bytes.
(setq gc-cons-threshold (* 50 1000 1000))

Native Compilation

Silence compiler warnings as they can be pretty disruptive

(setq native-comp-async-report-warnings-errors nil)

Encoding

From Doom emacs Contrary to what many Emacs users have in their configs, you don’t need more than this to make UTF-8 the default coding system:

(set-language-environment "UTF-8")

Path

Load environment variables from the shell

;;(use-package add-node-modules-path)
(use-package exec-path-from-shell
  :ensure t
  :init (exec-path-from-shell-initialize)
  :config
  (setq exec-path-from-shell-variables '("GOPATH" "PATH" "MANPATH")))

Set the start point for the current buffer, this means if you will search for a file, the start point will be the default-directory value.

(setq default-directory "~/")

Keep .emacs.d clean

I don’t want a bunch of transient files showing up as untracked in the Git repo so I move them all to another location.

 (setq custom-file
	  (if (boundp 'server-socket-dir)
	      (expand-file-name "custom.el" server-socket-dir)
	    (expand-file-name (format "emacs-custom-%s.el" (user-uid)) temporary-file-directory)))
 (add-hook 'elpaca-after-init-hook (lambda () (load custom-file 'noerror)))


 (setq backup-directory-alist
	`((".*" . ,temporary-file-directory))
	auto-save-file-name-transforms
	`((".*" ,temporary-file-directory t))
	create-lockfiles nil)

 (setq tramp-auto-save-directory temporary-file-directory)

Look & Feel

Improve theme loading

Source: Reddit

(defadvice load-theme (before clear-previous-themes activate)
  "Clear existing theme settings instead of layering them"
  (mapc #'disable-theme custom-enabled-themes))

Theme

Doom Themes

(use-package doom-themes
  :ensure t
  :preface
  (setq
   doom-themes-treemacs-theme "doom-colors"
   dark-theme "doom-tokyo-night"
   light-theme "doom-fairy-floss")
  :init
  (load-theme (intern dark-theme) t)

  (defun gg-switch-theme()
    (interactive)
    (let* ((theme (car custom-enabled-themes))
           (change (if (string= theme light-theme) dark-theme light-theme)))
      (load-theme (intern change) t)
      (setq selected-theme change)
      (message "Theme switched from %s to %s" theme change)))
  (global-set-key (kbd "<f8>") 'gg-switch-theme)

  :config
  (doom-themes-neotree-config)
  (with-eval-after-load 'doom-themes
    (doom-themes-treemacs-config))
  (set-face-attribute 'default nil :font "Menlo 13")
  (set-face-attribute 'region nil :background "#000" :foreground "#ffffff"))

Neotree

(defun text-scale-twice ()
  (interactive)
  (progn(text-scale-adjust 0)(text-scale-decrease 2)))

(use-package neotree
  :ensure t
  :bind([f9] . neotree-toggle)
  :hook (neo-after-create . (lambda (_)(call-interactively 'text-scale-twice)))
  :config
  (setq neo-autorefresh nil)
  (setq neo-smart-open t)
  (with-eval-after-load 'neotree
    (define-key neotree-mode-map (kbd "h") 'neotree-hidden-file-toggle)))

Icons

(use-package all-the-icons :ensure t)
(use-package all-the-icons-dired
  :ensure t
  :hook (dired-mode . all-the-icons-dired-mode))

Nyan cat

(use-package nyan-mode
  :ensure t
  :init
  (nyan-mode t))

Emoji

(use-package emojify
  :ensure t
  :hook (elpaca-after-init . global-emojify-mode))

Emacs interface

(scroll-bar-mode 0)
(column-number-mode)
(setq ring-bell-function 'ignore)

Writing yes or no is length, type y / n instead

(defalias 'yes-or-no-p 'y-or-n-p)

Android toolbar

(defun android-toggle-keyboard()
  (interactive)
  (if touch-screen-display-keyboard
      (progn
        (setq touch-screen-display-keyboard nil)
        (tool-bar-add-item
         "keyboard-off" 'android-toggle-keyboard
         'android-toggle-keyboard
         :help "Toggle keyboard")
        (message "Disable virtual keyboard"))
    (setq touch-screen-display-keyboard t)
    (tool-bar-add-item
     "keyboard" 'android-toggle-keyboard
     'android-toggle-keyboard
     :help "Toggle keyboard")
    (message "Enable virtual keyboard")))

(defun android-tool-bar-configs()
  (when (and (fboundp 'tool-bar-mode)
             (string-equal system-type "android"))

    (tool-bar-mode +1)
    (setq! tool-bar-position 'bottom)
    (setq! tool-bar-button-margin 27)

    (setq tool-bar-map '(keymap nil))

    (add-to-list 'image-load-path (expand-file-name "icons" user-emacs-directory))

    (android-general-tool-bar 'tool-bar-add-item nil)


    ))

(defun android-general-tool-bar(fun map)
  (mapc (lambda (args)
          (apply fun args))
        `(("keyboard-esc" tool-bar-item-escape keyboard-esc ,map)
          ("file-find-outline" find-file file-find-outline ,map)
          ("keyboard-off" android-toggle-keyboard android-toggle-keyboard ,map)
          ("calendar-multiselect" (lambda () (interactive) (org-agenda nil "z")) android-toggle-keyboard ,map)
          ))
  )

(define-key key-translation-map [tool-bar apple-keyboard-command] #'tool-bar-event-apply-control-modifier)
(define-key key-translation-map (kbd "<XF86Back>") [escape])
(define-key key-translation-map [tool-bar keyboard-esc] [escape])
(define-key key-translation-map [tool-bar keyboard-tab]  (kbd "TAB"))

Doom modeline

(use-package doom-modeline
  :ensure t
  :config
  (setq doom-modeline-height 35)
  (set-face-background 'doom-modeline-bar (face-background 'mode-line))
  (setq doom-modeline-bar-width 1)
  (doom-modeline-mode 1))

Dialog

Don’t pop up UI dialogs when prompting

(setq use-dialog-box nil)

Company

(use-package company
  :ensure t
  :hook (prog-mode . company-mode)
  :config
  (setq company-minimum-prefix-length 2)
  (global-company-mode)
  (global-set-key (kbd "TAB") #'company-indent-or-complete-common))

(setq company-tooltip-align-annotations t)

(use-package company-box
  :ensure t
  :hook (company-mode . company-box-mode))

Editing

;; Remembering the last place you visited in a file
(save-place-mode 1)

(setq-default truncate-lines t ;; Do not wrap lines
              indent-tabs-mode nil) ;; spaces instead of tabs

(setq show-trailing-whitespace t ;; Complain about trailing white spaces
      whitespace-style '(face trailing lines tabs big-indent)) ;; Cleanup white spaces before save

;; Cleanup whitespace before save
(add-hook 'before-save-hook 'whitespace-cleanup)

Yank ring

(global-set-key (kbd "C-M-y") 'yank-pop)

Parenthesis

(use-package smartparens
  :ensure t
  :config
  (smartparens-global-mode t))

(use-package rainbow-delimiters
  :ensure t
  :hook (prog-mode . rainbow-delimiters-mode))

(use-package rainbow-mode :ensure t)

(use-package string-inflection
  :ensure t
  :bind ("C-c i" . string-inflection-cycle))

(global-hl-line-mode t)

Display line numbers

(add-hook 'prog-mode-hook #'display-line-numbers-mode)
(add-hook 'conf-mode-hook #'display-line-numbers-mode)

Indent Guides

(use-package highlight-indent-guides
  :ensure t
  :config
  (setq highlight-indent-guides-method 'character))

Multiple cursor

(use-package multiple-cursors
  :ensure t
  :bind (("A-S-c A-S-c" . mc/edit-lines)
	   ("C-." . mc/mark-next-like-this)
	   ("C-," . mc/mark-previous-like-this)
	   ("A->" . mc/mark-all-like-this)
	   ("C-A-<mouse-1>" . mc/add-cursor-on-click)))

Unfill paragraph

(defun unfill-paragraph (&optional region)
  "Takes a multi-line paragraph or (REGION) and make it into a single line of text."
  (interactive (progn (barf-if-buffer-read-only) '(t)))
  (let ((fill-column (point-max))
        ;; This would override `fill-column' if it's an integer.
        (emacs-lisp-docstring-fill-column t))
    (fill-paragraph nil region)))

Treesiter

(require 'treesit)
;; modules build from https://github.com/casouri/tree-sitter-module
(setq treesit-extra-load-path '("~/Projects/tree-sitter-module/dist"))
(push '(css-mode . css-ts-mode) major-mode-remap-alist)
(push '(javascript-mode . js-ts-mode) major-mode-remap-alist)
(push '(js-json-mode . json-ts-mode) major-mode-remap-alist)
(push '(typescript-mode . typescript-ts-mode) major-mode-remap-alist)
(push '(typescript-mode . tsx-ts-mode) major-mode-remap-alist)
(push '(ruby-mode . ruby-ts-mode) major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . tsx-ts-mode))

Flyspell

(use-package flyspell
  :ensure nil
  :bind (("<f7>" . 'fd-switch-dictionary)
         ("C-;" . 'flyspell-correct-wrapper)))

(use-package flyspell-correct-popup
  :ensure t
  :config
  (setq ispell-program-name "aspell")
  (ispell-change-dictionary "pt_BR"))

(defun fd-switch-dictionary()
  (interactive)
  (let* ((dic ispell-current-dictionary)
         (change (if (string= dic "pt_BR") "english" "pt_BR")))
    (ispell-change-dictionary change)
    (message "Dictionary switched from %s to %s" dic change)))

;; (global-set-key (kbd "<f7>") )
;; (define-key flyspell-mode-map (kbd "C-;") 'flyspell-correct-wrapper)

Yasnippet

(use-package yasnippet
  :ensure t
  :init
  :config
  (yas-load-directory "~/.emacs.d/snippets")
  (yas-global-mode 1))

Org

(use-package org
  :ensure nil
  :custom
  (org-agenda-files
   '(
     "/Users/guerra/Projects/org-files/roam/20230102102131-financeiro.org"
     "/Users/guerra/Projects/org-files/roam/20230102103928-pessoal.org"
     "/Users/guerra/Projects/org-files/roam/20230402214745-the_clear_cut.org"
     ))
  (org-agenda-span 15)
  (org-deadline-warning-days 0)
  (org-icalendar-deadline-summary-prefix "")
  (org-icalendar-timezone "")
  (org-icalendar-use-deadline '(event-if-todo todo-due))
  (org-icalendar-with-timestamps nil)
  :bind (("C-c a" . (lambda () (interactive) (org-agenda nil "z")) )
         ("C-c /" . 'org-capture)
         ("s-c" . 'ox-clip-formatted-copy))
  :hook (org-mode . turn-on-flyspell))

(use-package org-contrib
  :ensure t
  :config
  (require 'org-inlinetask)
  (require 'org-tempo)
  (require 'org-collector)  )

(use-package org-web-tools
  :ensure t
  :custom
  (org-web-tools-pandoc-sleep-time 1.8))

(use-package git-auto-commit-mode :ensure t)
(use-package ox-clip :ensure t)

(setq org-export-coding-system 'utf-8
      org-directory "~/Projects/org-files/"
      org-tag-alist '(("work" . ?w) ("personal" . ?p) ("meta" . ?m) ("emacsLove" . ?l) ("quotes" . ?q) ("finances" . ?f) ("howto" . ?h))
      org-log-done nil
      org-log-repeat nil
      org-startup-indented t
      org-export-with-toc nil
      org-export-with-section-numbers nil
      gac-automatically-push-p t)

Ox

Slack

(use-package ox-slack
  :ensure t
  :bind ("C-c e s" . org-slack-export-to-clipboard-as-slack))

Reveal

 (use-package ox-reveal :ensure t)
 (setq org-reveal-root "https://cdn.jsdelivr.net/npm/reveal.js"
	org-reveal-title-slide nil
	org-reveal-mathjax t)
 (use-package htmlize :ensure t)

Look & Feel

Olivetti

(use-package olivetti
  :ensure t
  :custom
  (olivetti-body-width 120))

Super-agenda

 (use-package org-super-agenda
   :ensure t
   :after org-agenda
   :config
   (org-super-agenda-mode t)
   (setq org-agenda-skip-scheduled-if-done t))

 (setq org-agenda-custom-commands
	'(("z" "Super view"
	   ((tags "meta" ((org-agenda-overriding-header "Objetivos de 2023")))
	    (agenda "" ((org-agenda-span 'week)
			(org-agenda-overriding-header "")
			))
	    (alltodo "" ((org-agenda-overriding-header "")
			 (org-agenda-remove-tags t)
			 (org-super-agenda-groups
			  '(
			    (:name "🚨 Atrasados"
				   :deadline past
				   :order 7)
			    (:name "Próximos eventos"
				   :discard (:tag ("finances"))
				   :deadline future
				   :order 8)
			    (:name "Sem data" :deadline nil :order 9)
			    (:discard (:tag ("Routine" "Daily" "meta" "finances")))))))
	    ))))

Functions

Check if a billing is paid based on the date

(defun is-paid? (time)
  (if (eq (string-to-number (format-time-string "%m")) (nth 4 (org-parse-time-string time)))
      "-" "pago"))

Add ID to all headings source

(defun add-id-to-tasks-in-file ()
  "Add ID properties to all tasks in the current file which
  do not already have one."
  (interactive)
  (org-ql-select (buffer-file-name)
    '(and
      (todo))
    :action #'org-id-get-create))

Roam

(use-package org-roam
  :ensure t
  :custom
  (org-roam-directory "~/Projects/org-files/roam")
  (setq org-roam-dailies-directory "daily/")
  (org-roam-completion-everywhere t)
  :bind (("C-c n l" . org-roam-buffer-toggle)
	   ("<f4>" . org-roam-node-find)
	   ("C-c n i" . org-roam-node-insert)
	   ("<f12>" . org-roam-dailies-goto-today)
	   ;; :map org-mode-map
	   ;; ("C-M-i" . completion-at-point)
	   :map org-roam-dailies-map
	   ("Y" . org-roam-dailies-capture-yesterday)
	   ("T" . org-roam-dailies-capture-tomorrow))
  :bind-keymap
  ("C-c n d" . org-roam-dailies-map)
  :config
  (require 'org-roam-dailies) ;; Ensure the keymap is available
  (org-roam-db-autosync-mode))

Sync

(defun org-agenda-export-to-ics ()
  (interactive)
  (org-icalendar-combine-agenda-files)
  (copy-file org-agenda-private-local-path org-agenda-private-remote-path t))

(use-package midnight
  :ensure nil
  :config
  (midnight-delay-set 'midnight-delay 16200)
  (setq midnight-period 2400 ;; in seconds
	  org-agenda-private-local-path "~/.org.ics"
	  org-agenda-private-remote-path "~/Google Drive/My Drive/org.ics")
  :hook (midnight . org-agenda-export-to-ics)
  :bind ("C-c e i" . org-agenda-export-to-ics))

Babel

(setq org-src-fontify-natively t)
(setq org-confirm-babel-evaluate nil)
(setq org-src-window-setup 'current-window)
(org-babel-do-load-languages
 'org-babel-load-languages
 '((python . t)
   (sql . t)))

Markdown

(use-package markdown-mode :ensure t)

Vertigo

(use-package vertico
  :ensure t
  :init
  (vertico-mode)
  :custom
  (vertico-group-separator ((t (:inherit all-the-icons-dorange :strike-through t))))
  (vertico-group-title ((t (:inherit all-the-icons-dorange :slant italic)))))

(use-package savehist
  :init
  (savehist-mode))

(use-package orderless
  :ensure t
  :custom
  (completion-styles '(orderless basic))
  (completion-category-overrides '((file (styles basic partial-completion)))))

Postframe

(use-package vertico-posframe
  :init (vertico-posframe-mode)
  :ensure t
  :config
  (setq vertico-multiform-commands
        '((consult-line (:not posframe))
          (consult-theme (:not posframe))
          (consult-ripgrep (:not posframe))
          (consult-org-heading (:not posframe))
          (consult-xref (:not posframe))
          (consult-imenu (:not posframe))
          (t posframe)))
  (setq vertico-posframe-parameters
        '((left-fringe . 8)
        (right-fringe . 8)))
  (vertico-multiform-mode t))

Consult

(use-package consult
  :ensure t
  :bind (("C-M-l" . consult-imenu)
         ("C-s" . consult-line)
         ("C-M-g" . consult-ripgrep)
         ("C-M-o" . consult-org-heading)
         ("C-x C-b" . consult-buffer)
         ("C-x b" . consult-project-buffer))
  :hook (completion-list-mode . consult-preview-at-point-mode)
  :init
  (autoload 'projectile-project-root "projectile")
  (setq register-preview-delay 0
        register-preview-function #'consult-register-format
        xref-show-xrefs-function #'consult-xref
        xref-show-definitions-function #'consult-xref))

Consult org

(use-package consult-org-roam
   :ensure t
   :after org-roam
   :init
   (require 'consult-org-roam)
   ;; Activate the minor mode
   (consult-org-roam-mode 1)
   :custom
   ;; Use `ripgrep' for searching with `consult-org-roam-search'
   (consult-org-roam-grep-func #'consult-ripgrep)
   ;; Configure a custom narrow key for `consult-buffer'
   (consult-org-roam-buffer-narrow-key ?r)
   ;; Display org-roam buffers right after non-org-roam buffers
   ;; in consult-buffer (and not down at the bottom)
   (consult-org-roam-buffer-after-buffers t)
   :config
   ;; Eventually suppress previewing for certain functions
   (consult-customize
    consult-org-roam-forward-links
    :preview-key (kbd "M-."))
   :bind
   ;; Define some convenient keybindings as an addition
   ("C-c n e" . consult-org-roam-file-find)
   ("C-c n b" . consult-org-roam-backlinks)
   ("C-c n l" . consult-org-roam-forward-links)
   ("C-c n r" . consult-org-roam-search))

which-key

(use-package which-key
  :ensure t
  :config
  (which-key-mode))

Commit

Javascript

(use-package js-comint :ensure t)

Read aloud

(use-package read-aloud
  :ensure t
  :config
  (setq read-aloud-engine "say"))