2023년에 emacs 28.2 를 사용해봅시다. (3) : 클리앙

config.org 공유합니다.

자세한 해설은 천천히 업데이트 하겠습니다.


#+title: Crafted Emacs Configuration File by meleeis#+PROPERTY: header-args:emacs-lisp :tangle ./config.el :mkdirp yes* org-babel-tangle-configCrafted Emacs supports user customization through a =config.org= file similar tothis one.To get you started,년에emacs를사용해봅시다클리앙 copy both example files to your Crafted Emacs configurationdirectory, e.g.:- copy =examples/example-config.el= to =~/.crafted-emacs/config.el=- copy =examples/example-config.org= to =~/.crafted-emacs/config.org=- restart EmacsAfter that, whenever you edit =config.org= in Emacs and save it, it updates=config.el= in the same directory.See the [[https://orgmode.org/manual/Extracting-Source-Code.html][Org Manual]] for details and alternatives.#+begin_src emacs-lisp    ;;; config.el -- Example Crafted Emacs user customization file -*- lexical-binding: t; -*-  ;; This file is generated from config.org. If you want to edit the  ;; configuration, DO NOT edit config.el, edit config.org, instead.  ;; Tangle the code blocks to config.el on save.  (defun org-babel-tangle-config ()    (when (string-equal (buffer-file-name)                        (expand-file-name "config.org" crafted-config-path))      ;; Dynamic scoping to the rescue      (let ((org-confirm-babel-evaluate nil))        (org-babel-tangle))))  (add-hook 'org-mode-hook            (lambda ()              (add-hook 'after-save-hook #'org-babel-tangle-config)))#+end_srcIn your configuration you can set any Emacs configuration variable, faceattributes, themes, etc as you normally would.See the README.org file in this repository for additional information.* Crafted Modules#+begin_src emacs-lisp  (require 'crafted-defaults)    ; Sensible default settings for Emacs  (require 'crafted-updates)     ; Tools to upgrade Crafted Emacs  (require 'crafted-completion)  ; selection framework based on `vertico`  (require 'crafted-ui)          ; Better UI experience (modeline etc.)  (require 'crafted-editing)     ; Whitspace trimming, auto parens etc.  (require 'crafted-org)         ; org-appear, clickable hyperlinks etc.  (require 'crafted-project)     ; built-in alternative to projectile  (require 'crafted-speedbar)    ; built-in file-tree  (require 'crafted-compile)     ; automatically compile some emacs lisp files  (require 'crafted-latex)  (require 'crafted-ide)  (require 'crafted-python)#+end_srcAt the moment, Crafted Emacs offers the following modules. Comment outeverything you don't want to use.At the very least, you should decide whether or not you want to use [[https://github.com/emacs-evil/evil][evil-mode]],as it will greatly change how you interact with Emacs. So, if you preferVim-style keybindings over vanilla Emacs keybindings remove the commentin the line about =crafted-evil= below.* Font and theme settings** Font settingsSet the default face. The default face is the basis for most otherfaces used in Emacs. A "face" is a configuration including font,font size, foreground and background colors and other attributes.The*-pitch and*-pitch-serif faces are monospace facesgenerally used as the default face for code. The variable-pitchface is used when `variable-pitch-mode' is turned on, generallywhenever a non-monospace face is preferred.#+begin_src emacs-lisp  (add-hook 'emacs-startup-hook            (lambda ()              (custom-set-faces               `(default ((nil (:family "DejaVu Sans Mono" :height 120))))               `(fixed-pitch ((nil (:family "DejaVu Sans Mono" :height 1.0))))               `(variable-pitch ((nil (:family "DejaVu Sans Serif" :height 1.0)))))))  (set-fontset-font t 'hangul "D2Coding")  (set-fontset-font t 'han "Noto Sans CJK SC")  ;;  (setq face-font-rescale-alist '(("D2Coding" . 1.3)  ;;                                  ("Noto Sans CJK SC" . 1.3)))  (if (daemonp)      (add-hook 'server-after-make-frame-hook                (lambda ()                  (set-face-attribute 'default nil :family "DejaVu Sans Mono" :height 120)                  (set-face-attribute 'fixed-pitch nil :family "DejaVu Sans Mono" :height 1.0)                  (set-face-attribute 'variable-pitch nil :family "DejaVu Sans Serif" :height 1.2)                  (set-fontset-font t 'hangul "D2Coding")                  (set-fontset-font t 'han "Noto Sans Mono CJK SC")                  (setq face-font-rescale-alist '(("D2Coding" . 1.3)                                                  ("Noto Sans CJK SC" . 1.3))))))#+end_src** Theme settings#+begin_src emacs-lisp  (crafted-package-install-package 'doom-themes)  (progn    (disable-theme 'deeper-blue)          ; first turn off the deeper-blue theme    (load-theme 'doom-palenight t))       ; load the doom-palenight theme#+end_src* Custom.elBy default, Crafted Emacs keeps your config file clean. All the customizationsettings that Emacs normally automatically adds to your config.el go intothe file =custom.el= instead. If you don't want this, set the respectivevariable to =nil=:#+begin_src emacs-lisp  ;; To not load `custom.el' after `config.el', uncomment this line.  ;; (setq crafted-load-custom-file nil)#+end_src* Tangling to early-config.elIf you need to make settings to =early-config.el=, you can do that from here, too.Just begin the source code block with:#+begin_src emacs-lisp :tangle ./early-config.el  (setq package-enable-at-startup nil)  (setq crafted-package-system 'straight)  (crafted-package-bootstrap crafted-package-system)#+end_src* Language setting#+begin_src emacs-lisp  ;; UTF-8 as default encoding  (set-language-environment "UTF-8")  (set-default-coding-systems 'utf-8)  (set-keyboard-coding-system 'utf-8-unix)  ;; do this especially on Windows, else python output problem  (set-terminal-coding-system 'utf-8-unix)  ;; windows coding system  (when (and (eq system-type 'windows-nt)             (eq w32-ansi-code-page 65001))    (setq w32-system-coding-system 'utf-8)    (define-coding-system-alias 'cp65001 'utf-8))  (setq system-time-locale "C") ;; 시간은 영어로.#+end_src** pyim setting#+begin_src emacs-lisp  (straight-use-package 'pyim)  (straight-use-package 'pyim-basedict)  (require 'pyim)  (require 'pyim-basedict)  (pyim-basedict-enable)  (straight-use-package 'posframe)  (require 'posframe)  (setq pyim-page-tooltip 'posframe)  ;;  (setq default-input-method "pyim")#+end_src** Input Setting#+begin_src emacs-lisp  (setq alternative-input-methods        '(("korean-hangul" . [?\C-\\])          ;;          ("rime" . [?\C-|])))          ("pyim" . [?\C-|])))  (setq default-input-method        (caar alternative-input-methods))  (defun toggle-alternative-input-method (method &optional arg interactive)    (if arg        (toggle-input-method arg interactive)      (let ((previous-input-method current-input-method))        (when current-input-method          (deactivate-input-method))        (unless (and previous-input-method                     (string= previous-input-method method))          (activate-input-method method)))))  (defun reload-alternative-input-methods ()    (dolist (config alternative-input-methods)      (let ((method (car config)))        (global-set-key (cdr config)                        `(lambda (&optional arg interactive)                           ,(concat "Behaves similar to `toggle-input-method', but uses \""                                    method "\" instead of `default-input-method'")                           (interactive "P\np")                           (toggle-alternative-input-method ,method arg interactive))))))  (reload-alternative-input-methods)  (global-set-key [?\S- ] 'toggle-input-method)#+end_src** keybinding Panel#+begin_src emacs-lisp  (straight-use-package 'which-key)  (which-key-mode)#+end_src* Writting** org-mode- C-c C-, :: (org-insert-structure-template)- C-x C-e :: eval-last-sexp#+begin_src emacs-lisp  (straight-use-package 'org)  (require 'org)  (setq org-directory "~/Documents/roam")  (setq org-default-notes-file (concat org-directory "/Inbox.org"))  ;; key binding  (global-set-key (kbd "C-c l") #'org-store-link)  (global-set-key (kbd "C-c a") #'org-agenda)  (global-set-key (kbd "C-c c") #'org-capture)  ;; cut and paste subtrees.  (with-eval-after-load 'org    (define-key org-mode-map (kbd "C-c k") 'org-cut-subtree)    (setq org-yank-adjusted-subtrees t))  ;; visual-line-mode  (add-hook 'org-mode-hook #'visual-line-mode)  (setq org-modules '(org-tempo org-habit))  (setq org-startup-with-inline-images t)  (setq org-src-tab-acts-natively t)  (org-babel-do-load-languages   'org-babel-load-languages '((emacs-lisp . t) (python . t) (latex .t)))  (setq org-image-actual-width 600)  (setq org-startup-folded 'content)  (setq org-structure-template-alist        '(("a" . "export ascii")          ("c" . "center")          ("C" . "comment")          ("e" . "example")          ("E" . "export")          ("h" . "export html")          ("l" . "export latex")          ("q" . "quote")          ("s" . "src")          ("py" . "src python")          ("el" . "src emacs-lisp")          ("sh" . "src shell")          ("v" . "verse")))  ;;Refile  (setq org-refile-use-outline-path 'file)  (setq org-outline-path-complete-in-steps nil)  (setq org-refile-targets '((nil :maxlevel . 1)                             (org-agenda-files :maxlevel . 1)))  (setq org-todo-keywords        '((sequence "TODO(t!)" "WAIT(w@/!)" "|" "DONE(d!)" "CANCELED(c@)")))  (setq org-agenda-include-diary t        diary-file "~/Documents/diary.org"        org-agenda-diary-file 'diary-file)  (setq org-agenda-start-on-weekday nil)#+end_src#+RESULTS:*** org-download mode#+begin_src emacs-lisp  (straight-use-package 'org-download)  (require 'org-download)  ;; Drag-and-drop to `dired`  (add-hook 'dired-mode-hook 'org-download-enable)  (setq org-download-method 'directory)  (setq org-download-image-dir "images")  (setq org-download-heading-lvl nil)  (setq org-download-timestamp "%Y%m%d-%H%M%S_")  (setq org-download-screenshot-method "xfce4-screenshooter -r -o cat > %s")  (defface org-link-internal    '((((class color) (background light)) (:foreground "turquoise1" :underline t))      (((class color) (background dark)) (:foreground "turquoise1" :underline t))      (t (:underline t)))    "Face for internal links."    :group 'org-faces)  (org-link-set-parameters "file"                           :face 'org-link-internal)  (defun org-download-wsl-clipboard()    "to simplify the logic, use c:/Users/Public as temporary directoy, and move it into current directoy. Win + Shift + S"    (interactive)    (let* ((powershell "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")           (file-name (format-time-string "%Y%m%d-%H%M%S_screenshot.png"))           ;; (file-path-powershell (concat "c:/Users/\$env:USERNAME/" file-name))           (file-path-wsl (concat "~/Documents/roam/images/" file-name))           )      ;; (shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/\\$env:USERNAME/" file-name "\\\")\""))      (shell-command (concat powershell " -command \"(Get-Clipboard -Format Image).Save(\\\"C:/Users/Public/" file-name "\\\")\""))      (rename-file (concat "C:/Users/Public/" file-name) file-path-wsl)      (insert (concat "\n#+DOWNLOADED: " "screenshot in wsl @ " (format-time-string "%Y-%m-%d %H:%M:%S") "\n" "[[file:" file-path-wsl "]]"))      (message "insert DONE.")))  (define-key org-mode-map (kbd "C-c d c") 'org-download-screenshot)  (define-key org-mode-map (kbd "C-c d d") 'org-download-delete)  (define-key org-mode-map (kbd "C-c d e") 'org-download-edit)  (define-key org-mode-map (kbd "C-c d v") 'org-download-wsl-clipboard)#+end_src** ripgrep#+begin_src emacs-lisp  (straight-use-package 'deadgrep)#+end_src** org-roamsystemcrafter "5 org roam hacks." + daviwill/dotfiles- org-roam-dailies-goto-date :: C-c n d c. use calendar goto date dailies journal.#+begin_src emacs-lisp  (straight-use-package 'org-roam)  (require 'org-roam)  (require 'org-roam-dailies) ;; Ensure the keymap is available  (require 'org-roam-protocol)  (setq org-roam-directory "~/Documents/roam/")  (setq org-roam-dailies-directory "Journal/")  (setq org-roam-completion-everywhere t)  (define-key org-mode-map (kbd "C-c n i") 'org-roam-node-insert)  (define-key org-mode-map (kbd "C-c n I") 'org-roam-node-insert-immediate)  (define-key org-mode-map (kbd "C-c n l") 'org-roam-buffer-toggle)  (define-key org-mode-map (kbd "C-M-i") 'completion-at-point)  (define-key org-mode-map (kbd "C-c n p") 'my/org-roam-find-project)  (define-key org-mode-map (kbd "C-c n t") 'my/org-roam-capture-task)  (define-key org-mode-map (kbd "C-c n b") 'my/org-roam-capture-inbox)  (define-key org-roam-dailies-map (kbd "Y") 'org-roam-dailies-capture-yesterday)  (define-key org-roam-dailies-map (kbd "T") 'org-roam-dailies-capture-tomorrow)  (global-set-key (kbd "C-c n f") #'org-roam-node-find)  (global-set-key (kbd "C-c n d") #'org-roam-dailies-map)  (add-hook 'org-agenda-mode-hook 'my/org-roam-refresh-agenda-list)  (setq dw/daily-note-filename "%<%Y-%m-%d>.org"        dw/daily-note-header "#+title: %<%Y-%m-%d %a>\n\n[[roam:%<%Y-%m>]]\n\n")  (setq org-roam-dailies-capture-templates        `(("d" "default" entry           "* %?"           :target (file+head ,dw/daily-note-filename                              ,dw/daily-note-header))          ("t" "task" entry           "* TODO %?\n  %U\n  %a\n  %i"           :target (file+head+olp ,dw/daily-note-filename                                  ,dw/daily-note-header                                  ("Tasks"))           :empty-lines 1)          ("l" "log entry" entry           "* %<%I:%M %p> - %?"           :target (file+head+olp ,dw/daily-note-filename                                  ,dw/daily-note-header                                  ("Log")))          ("j" "journal" entry           "* %<%I:%M %p> - Journal  :journal:\n\n%?\n\n"           :target (file+head+olp ,dw/daily-note-filename                                  ,dw/daily-note-header                                  ("Log")))          ("m" "meeting" entry           "* %<%I:%M %p> - %^{ Meeting Title}  :meetings:\n\n%?\n\n"           :target (file+head+olp ,dw/daily-note-filename                                  ,dw/daily-note-header                                  ("Log")))))  (defvar dw/org-roam-project-template    '("p" "project" plain "** TODO %?"      :target (file+head+olp "%<%Y%m%d%H%M%S>-${ slug}.org"                             "#+title: ${ title}\n#+category: ${ title}\n#+filetags: Project\n"                             ("Tasks"))))  (defun my/org-roam-filter-by-tag (tag-name)    (lambda (node)      (member tag-name (org-roam-node-tags node))))  (defun my/org-roam-list-notes-by-tag (tag-name)    (mapcar #'org-roam-node-file            (seq-filter             (my/org-roam-filter-by-tag tag-name)             (org-roam-node-list))))  ;; Bind this to C-c n I  (defun org-roam-node-insert-immediate (arg &rest args)    (interactive "P")    (let ((args (push arg args))          (org-roam-capture-templates (list (append (car org-roam-capture-templates)                                                    '(:immediate-finish t)))))      (apply #'org-roam-node-insert args)))  (defun my/org-roam-capture-task ()    (interactive)    ;; Add the project file to the agenda after capture is finished    (add-hook 'org-capture-after-finalize-hook #'my/org-roam-project-finalize-hook)    ;; Capture the new task, creating the project file if necessary    (org-roam-capture- :node (org-roam-node-read                              nil                              (my/org-roam-filter-by-tag "Project"))                       :templates (list dw/org-roam-project-template)))  (defun my/org-roam-refresh-agenda-list ()    (interactive)    (setq org-agenda-files (my/org-roam-list-notes-by-tag "Project")))  ;; Build the agenda list the first time for the session  (org-roam-db-autosync-mode)  (defun my/org-roam-project-finalize-hook ()    "Adds the captured project file to `org-agenda-files' if the                    capture was not aborted."    ;; Remove the hook since it was added temporarily    (remove-hook 'org-capture-after-finalize-hook #'my/org-roam-project-finalize-hook)    ;; Add project file to the agenda list if the capture was confirmed    (unless org-note-abort      (with-current-buffer (org-capture-get :buffer)        (add-to-list 'org-agenda-files (buffer-file-name)))))  (defun my/org-roam-find-project ()    (interactive)    ;; Add the project file to the agenda after capture is finished    (add-hook 'org-capture-after-finalize-hook #'my/org-roam-project-finalize-hook)    ;; Select a project file to open, creating it if necessary    (org-roam-node-find     nil     nil     (my/org-roam-filter-by-tag "Project")     nil     :templates     '(("p" "project" plain "\n* Goals\n\n%?\n\n* Tasks\n\n** TODO Add initial tasks\n\n* Dates\n\n"        :target (file+head "%<%Y%m%d%H%M%S>-${ slug}.org" "#+title: ${ title}\n#+category: ${ title}\n#+filetags: Project\n")        :unnarrowed t))))  (defun my/org-roam-capture-inbox ()    (interactive)    (org-roam-capture- :node (org-roam-node-create)                       :templates '(("i" "inbox" plain "* %?"                                     :target (file+head "Inbox.org" "#+title: Inbox\n")))))  (setq org-roam-mode-sections        (list #'org-roam-backlinks-section              #'org-roam-reflinks-section              ;; #'org-roam-unlinked-references-section              ))#+end_src** org-roam-ui#+begin_src emacs-lisp  (straight-use-package 'org-roam-ui)  (setq org-roam-ui-sync-theme t        org-roam-ui-follow t        org-roam-ui-update-on-save t        org-roam-ui-open-on-start nil)#+end_src* chinese calendar#+begin_src emacs-lisp  (require 'cal-china)  (defun my-diary-chinese-anniversary (lunar-month lunar-day &optional year mark)    (if year        (let* ((d-date (diary-make-date lunar-month lunar-day year))               (a-date (calendar-absolute-from-gregorian d-date))               (c-date (calendar-chinese-from-absolute a-date))               (cycle (car c-date))               (yy (cadr c-date))               (y (+ (* 100 cycle) yy)))          (diary-chinese-anniversary lunar-month lunar-day y mark))      (diary-chinese-anniversary lunar-month lunar-day year mark)))  (setq calendar-mark-holidays-flag t)  ; Use this instead  (setq calendar-mark-diary-entries-flag t)  (setq calendar-holidays        (append holiday-oriental-holidays))  ;; All are treated like weekdays (gray color)  (setq calendar-weekend-days nil)  ;; All are treated like weekends (red-faint color)  (setq calendar-weekend-days (number-sequence 0 6))  ;; The default marks the Saturday and Sunday as the weekend  (setq calendar-weekend-days '(0 6))#+end_src* Custom settings#+begin_src emacs-lisp  (require 'server)  (unless (server-running-p)    (server-start))  (setq find-file-visit-truename t)  (setq image-use-external-converter t)  (setq use-dialog-box nil)  (setq backup-by-copying t      ; don't clobber symlinks        backup-directory-alist '(("." . "~/.config/emacs/backup"))    ; don't litter my fs tree        delete-old-versions t        kept-new-versions 10        kept-old-versions 20        version-control t)       ; use versioned backups  (setq vc-make-backup-files t)  (setq prettify-symbols-unprettify-at-point 'right-edge)  (remove-hook 'pyvenv-post-activate-hooks #'pyvenv-restart-python)  (when ON-WINDOWS    (require 'browse-url)    (setq browse-url-generic-program "c:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"          browse-url-browser-function 'browse-url-generic          search-web-default-browser 'browse-url-generic))#+end_src* easyPG#+begin_src emacs-lisp  ;; (require 'epa-file)  ;; (setq epg-gpg-program "gpg2")  ;; (setenv "GPG_AGENT_INFO" nil)  ;; (setq epg-pinentry-mode 'loopback)  ;; (setq epa-file-cache-passphrase-for-symmetric-encryption t)  ;; (setq epa-file-select-keys t)  ;; (setq auth-source-debug t)  ;; (setq auth-sources  ;;       '((:source "~/.authinfo.gpg")))  ;; (setq smtpmail-auth-credentials (expand-file-name "~/.authinfo.gpg"))#+end_src

유용한사이트