commit 25cab92932b3fb9128c1563a1bf7043daa78b906 Author: Rafal Paluch Date: Thu May 8 09:12:42 2025 +0000 start diff --git a/README.md b/README.md new file mode 100644 index 0000000..060ff0f --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Emacs minimum diff --git a/init.el b/init.el new file mode 100644 index 0000000..b82adf2 --- /dev/null +++ b/init.el @@ -0,0 +1,588 @@ +;; ---------------------------- +;; Podstawowa konfiguracja pakietów i MELPA +;; ---------------------------- +(require 'package) + + +(add-hook 'python-mode-hook #'font-lock-mode) + + +;; Dodaj repozytoria +(setq package-archives '(("melpa" . "https://melpa.org/packages/") + ("gnu" . "https://elpa.gnu.org/packages/") + ("org" . "https://orgmode.org/elpa/"))) + +;; Inicjalizuj system pakietów +(package-initialize) + +;; Odśwież listę pakietów, jeśli jest pusta +(unless package-archive-contents + (package-refresh-contents)) + + +;; Funkcja do instalowania pakietów +(defun ensure-package-installed (&rest packages) + "Ensure that the given PACKAGES are installed. +Missing packages are automatically installed." + (dolist (package packages) + (unless (package-installed-p package) + (package-install package)))) + + + + + +;; Instalacja wymaganych pakietów +(ensure-package-installed + 'use-package + 'vterm + 'blacken + 'pyvenv + 'lsp-mode + 'lsp-ui + 'flycheck + 'org-roam + 'company + 'jupyter + 'scad-mode + 'treemacs + 'yasnippet + 'winum + 'lsp-treemacs) + + + + +;; Wczytaj i skonfiguruj `use-package` +(unless (package-installed-p 'use-package) + (package-install 'use-package)) +(require 'use-package) +(setq use-package-always-ensure t) + + +(when (eq system-type 'windows-nt) + ;; Popraw kodowanie dla Windows + (set-language-environment "UTF-8") + (prefer-coding-system 'utf-8)) + +;; python offset +(setq python-indent-guess-indent-offset nil) +(setq python-indent-offset 4) +(setq python-indent-guess-indent-offset-verbose nil) + + + + +;; ---------------------------- +;; Winum +;; ---------------------------- + +;; Przełączanie się między oknami +(use-package winum + :ensure t + :config + (winum-mode)) + + + +;; ---------------------------- +;; Konfiguracja yasnippet +;; ---------------------------- + +(use-package yasnippet + :ensure t + :config + (yas-global-mode 1)) ;; Włącz YASnippet globalnie + (setq yas-snippet-dirs '("~/.emacs.d/snippets")) ;; Ścieżka do własnych snippetów + +(use-package yasnippet-snippets + :ensure t + :after yasnippet) ;; Wymaga załadowanego yasnippet + + + + +;; ---------------------------- +;; Instalacja i konfiguracja LSP dla Python +;; ---------------------------- +(use-package lsp-mode + :ensure t + :hook ((python-mode . lsp)) ;; Automatyczne uruchamianie LSP w Python-mode + :commands lsp + :config + ;; Ustawienia LSP + (setq-default flycheck-disabled-checkers '(python-pylint python-flake8)) + (setq lsp-headerline-breadcrumb-enable t) ;; Breadcrumb w nagłówku + (setq lsp-completion-provider :capf) ;; Włączenie podpowiedzi capf + (setq lsp-enable-snippet t) ;; Włączenie snippetów w podpowiedziach + (setq lsp-pyright-auto-import-completions t) ;; Automatyczne podpowiedzi importów + (setq lsp-pyright-diagnostic-mode "workspace") ;; Diagnostyka w kontekście projektu + (setq lsp-pylsp-plugins-pyflakes-enabled nil) ;; Wyłącz pyflakes + (setq lsp-diagnostics-provider :none) ;; Wyłącz diagnostykę LSP na rzecz Flycheck + (setq lsp-pylsp-plugins-ruff-enabled t) ;; Użyj flake8 zamiast pyflakes + + + + ;; Ścieżka do interpretera Python + (setq lsp-pyright-python-executable-cmd "python3")) + + + +(use-package lsp-ui + :ensure t + :hook (lsp-mode . lsp-ui-mode) + :config + ;; Ustawienia lsp-ui + (setq lsp-ui-doc-enable t) ;; Dokumentacja w wyskakującym oknie + (setq lsp-ui-doc-position 'at-point) + (setq lsp-ui-sideline-enable t) ;; Diagnostyka w wierszu kodu + (setq lsp-ui-sideline-show-hover t) ;; Podpowiedzi w wierszu + (setq lsp-ui-sideline-show-code-actions t)) ;; Akcje kodu + + +;; ;; ---------------------------- +;; ;; Flycheck - konfiguracja diagnostyki +;; ;; ---------------------------- +(use-package flycheck + :ensure t + :hook ((lsp-mode . flycheck-mode) ;; Włącz Flycheck w trybie LSP + (emacs-lisp-mode . flycheck-mode)) ;; Włącz Flycheck w trybie Emacs Lisp + :config + ;; Priorytet diagnostyki LSP + (setq flycheck-check-syntax-automatically '(save mode-enabled)) + (setq flycheck-highlighting-mode 'lines) + (setq flycheck-indication-mode 'right-fringe)) + + +(use-package lsp-ui-flycheck + :after (lsp-mode flycheck) + :ensure nil) + +(defun set-flycheck-executables () + "Set Flycheck executables to use from the active Python virtual environment." + (when (and (boundp 'pyvenv-virtual-env) pyvenv-virtual-env) + (let* ((flake8-path (concat pyvenv-virtual-env + (if (eq system-type 'windows-nt) + "/Scripts/flake8.exe" ; Ścieżka na Windows + "/bin/flake8"))) ; Ścieżka na Linux/Mac + (pylint-path (concat pyvenv-virtual-env + (if (eq system-type 'windows-nt) + "/Scripts/pylint.exe" ; Ścieżka na Windows + "/bin/pylint")))) ; Ścieżka na Linux/Mac + (when (file-executable-p flake8-path) + (flycheck-set-checker-executable 'python-flake8 flake8-path)) + (when (file-executable-p pylint-path) + (flycheck-set-checker-executable 'python-pylint pylint-path))))) +(add-hook 'flycheck-before-syntax-check-hook #'set-flycheck-executables) + + + +;; ---------------------------------- +;; Obsługa venv z automatyczną aktywacją (Linux / Windows) +;; ---------------------------------- + +(use-package pyvenv + :ensure t + :config + (defun my-auto-activate-venv () + "Automatycznie aktywuj venv zależnie od systemu operacyjnego." + (let ((venv-path + (cond + ((eq system-type 'gnu/linux) "/home/pali112/venv") + ((eq system-type 'windows-nt) "C:/Users/paluc/OneDrive/Dokumenty/venv")))) + (when (and venv-path (file-directory-p venv-path)) + (pyvenv-activate venv-path) + (setq lsp-pyright-python-executable-cmd + (expand-file-name + (if (eq system-type 'windows-nt) + "Scripts/python.exe" + "bin/python") + venv-path))))) + (add-hook 'python-mode-hook #'my-auto-activate-venv)) + + + + + + + + +;; ---------------------------- +;; Kolorowe oznaczenie trybu EVIL w modeline +;; ---------------------------- + +(defface evil-normal-tag + '((t (:background "#87D7FF" :foreground "black" :weight bold))) + "Styl dla NORMAL state.") + +(defface evil-insert-tag + '((t (:background "#87FF5F" :foreground "black" :weight bold))) + "Styl dla INSERT state.") + +(defface evil-replace-tag + '((t (:background "#FF5F5F" :foreground "black" :weight bold))) + "Styl dla REPLACE state.") + +(defface evil-visual-line-tag + '((t (:background "#ffaf87" :foreground "black" :weight bold))) + "Styl dla VISUAL LINE state.") + +(defvar evil-mode-line-tag "" + "Zmienna przechowująca kolorowy tag trybu evil.") + +(defun update-evil-mode-line-tag () + "Aktualizuje kolorowy tag trybu evil w modeline." + (setq evil-mode-line-tag + (cond + ((evil-normal-state-p) + (propertize " NORMAL " 'face 'evil-normal-tag)) + ((evil-insert-state-p) + (propertize " INSERT " 'face 'evil-insert-tag)) + ((evil-replace-state-p) + (propertize " REPLACE " 'face 'evil-replace-tag)) + ((and (evil-visual-state-p) (eq evil-visual-selection 'line)) + (propertize " V-LINE " 'face 'evil-visual-line-tag)) + (t ""))) + (force-mode-line-update)) + +(add-hook 'post-command-hook #'update-evil-mode-line-tag) + +;; ---------------------------- +;; Pokazywanie aktywnego VENV +;; ---------------------------- + +(defun my-get-current-venv () + "Zwraca nazwę aktywnego środowiska wirtualnego." + (if (and (boundp 'pyvenv-virtual-env) pyvenv-virtual-env) + (propertize (concat " venv: " (file-name-nondirectory + (directory-file-name pyvenv-virtual-env))) + 'face '(:foreground "green" :weight bold)) + (propertize " No venv" 'face '(:foreground "gray")))) + +;; ---------------------------- +;; Finalny pasek mode-line +;; ---------------------------- + + + +(setq-default mode-line-format + (list + ;; TRYB EVIL + '(:eval evil-mode-line-tag) + " " + ;; NUMER OKNA + '(:eval (format " #%d " (winum-get-number))) + " " + ;; NAZWA BUFORA + 'mode-line-buffer-identification + " " + ;; LINIA:KOLUMNA + "%l:%c " + ;; PROGRESS W PLIKU + "%p " + ;; TRYBY (np. Python, LSP itp.) + 'mode-line-modes + " " + ;; VENV + '(:eval (my-get-current-venv)))) + + + +;; Skróty klawiszowe dla pyvenv +(global-set-key (kbd "C-c v a") 'pyvenv-activate) ;; Aktywuj środowisko +(global-set-key (kbd "C-c v d") 'pyvenv-deactivate) ;; Dezaktywuj środowisko +(global-set-key (kbd "C-c v w") 'pyvenv-workon) ;; Przełącz środowisko (workon) + + +;; (add-hook 'pyvenv-post-activate-hooks #'my-update-pyvenv-modeline) +;; (add-hook 'pyvenv-post-deactivate-hooks #'my-update-pyvenv-modeline) + + + + +;; ---------------------------- +;; System podpowiedzi: Company +;; ---------------------------- +(use-package company + :ensure t + :hook (lsp-mode . company-mode) + :config + (setq company-idle-delay 0.2) ;; Opóźnienie podpowiedzi + (setq company-minimum-prefix-length 1) ;; Minimalna długość prefiksu dla podpowiedzi + (setq company-selection-wrap-around t)) ;; Zawijanie w menu podpowiedzi + + + + +(use-package treemacs + :ensure t + :config + (global-set-key (kbd "C-c t") 'treemacs) ;; Skrót do otwierania Treemacs + (setq treemacs-position 'right) ;; Pozycja drzewa po prawej stronie + (setq treemacs-follow-mode t) ;; Automatyczne śledzenie otwartego pliku + (setq treemacs-filewatch-mode t) ;; Automatyczne odświeżanie + (setq treemacs-git-mode 'deferred)) ;; Obsługa Git w Treemacs + +(use-package lsp-treemacs + :ensure t + :after (lsp-mode treemacs) + :config + (lsp-treemacs-sync-mode 1)) + +;; ---------------------------- +;; Ulepszenia interfejsu: which-key +;; ---------------------------- +(use-package which-key + :ensure t + :config + (which-key-mode) + (setq which-key-idle-delay 0.5) ;; Opóźnienie wyświetlania podpowiedzi + (setq which-key-idle-secondary-delay 0.1)) + +;; ---------------------------- +;; Konfiguracja Evil i lidera (leader key) +;; turbo +;; ---------------------------- +(use-package evil + :ensure t + :config + (evil-mode 1)) +(evil-ex-define-cmd "hs" 'split-window-below) + +(use-package evil-leader + :ensure t + :config + (global-evil-leader-mode) + (evil-leader/set-leader "") + (evil-leader/set-key + "o o" 'my-open-todo-file + "o n" 'my-open-note-file + "o t" 'org-toggle-inline-imageS + "o f" 'org-overview + "o c" 'org-insert-link + "o l" 'org-agenda-list + "o i" 'org-clock-in + "o s" 'org-clock-out + "o r" 'org-clock-report + "r i" 'org-roam-node-insert + "g n" 'remote-nadpisz + "f f" 'find-file + "b l" 'ibuffer + "b w" 'buffer-menu-open + "t t" 'treemacs + "t a" 'treemacs-add-project-to-workspace + "t r" 'treemacs-remove-project-from-workspace + "t c" 'treemacs-copy-file + "t f" 'treemacs-create-file + "t m" 'treemacs-rename-file + "l l" 'toggle-truncate-lines + "l n" 'display-line-numbers-mode + "j s" 'jupyter-run-server-repl + "j a" 'jupyter-repl-associate-buffer + "j j" 'jupyter-eval-line-or-region + "p s" 'run-python + "p b" 'python-shell-send-buffer + "p r" 'python-shell-send-region + "s r" 'query-replace + "e l" 'flycheck-list-errors + "n n" 'narrow-to-region + "n w" 'widen + "a" 'mark-whole-buffer + "TAB" (lambda () (interactive) (switch-to-buffer (other-buffer))) + "1" 'winum-select-window-1 + "2" 'winum-select-window-2 + "3" 'winum-select-window-3 + "4" 'winum-select-window-4 + "5" 'winum-select-window-5)) + +(which-key-add-key-based-replacements + " e" "Errors" + " n" "Narrow" + " f" "Files" + " b" "Buffers" + " r" "Roam" + " t" "Treemacs" + " l" "Lines" + " j" "Jupyter" + " s" "Search&Replace" + " o" "Org" + " m" "Macro" + " p" "Python" + ) + + +;; Utwórz mapę klawiszy dla "SPC" +(define-prefix-command 'my-space-prefix) +(define-key evil-normal-state-map (kbd "SPC") 'my-space-prefix) + +;; Dodaj mapowanie "SPC 0" do Treemacs +(define-key my-space-prefix (kbd "0") 'my-treemacs-select-or-open) + +;; Funkcja, która przełącza się na okno Treemacs lub je otwiera +(defun my-treemacs-select-or-open () + "Przełącz się na okno Treemacs lub otwórz Treemacs, jeśli nie jest aktywne." + (interactive) + (if (treemacs-get-local-window) + (treemacs-select-window) + (treemacs))) + +;; ---------------------------- +;; Dodanie obsługi komentowania za pomocą "gc" +;; ---------------------------- +(use-package evil-commentary + :ensure t + :after evil + :config + (evil-commentary-mode)) + + +;; ---------------------------- +;; Wygląd: Motyw i minimalistyczny interfejs +;; ---------------------------- + + (use-package gruvbox-theme + :ensure t + :config + (load-theme 'gruvbox-dark-medium t)) + + (tool-bar-mode -1) + (menu-bar-mode -1) + (setq inhibit-startup-message t) + + + +;; ---------------------------- +;; Formatowanie kodu z Black +;; ---------------------------- +(use-package blacken + :ensure t + :hook (python-mode . blacken-mode) + :config + (setq blacken-line-length 88)) + + + + +;; ---------------------------- +;; Podsumowanie i test +;; ---------------------------- +(recentf-mode 1) +(setq recentf-max-menu-items 25) ;; Maksymalna liczba plików na liście +(global-set-key (kbd "C-c r") 'recentf-open-files) ;; Skrót do ostatnich plików + +;; ---------------------------- +;; Other keys +;; ---------------------------- +(global-set-key (kbd "C-c s e") 'eshell) +(global-set-key (kbd "C-c d") 'flycheck-list-errors) +(global-set-key (kbd "C-c o f") 'save-image-from-clipboard) ;; Zapisz zdjęcie + +(global-set-key (kbd "C-c j s") 'jupyter-run-server-repl) ;; Połącz się z serwerem +(global-set-key (kbd "C-c j a") 'jupyter-repl-associate-buffer) ;; Powiąż bufor z REPL +(global-set-key (kbd "C-c j b") 'jupyter-eval-buffer) ;; Wykonaj cały bufor + + + "m v" 'vosk-start + +(setq initial-scratch-message (concat ";; Aby otworzyć org todo daj na SPC o o \n" + ";; Aby otworzyć org notatki daj na SPC o n \n" + ";; Aby przesuwać nagłówki w Org dajsz shift + j lub l \n" + ";; W git jeśli wysyłasz to g g P p, a pull gg F p \n" + ";; Aby odpalić VOSK daj na SPC m v \n" + ";; Aby otworzyć eshell daj na C-c s e \n" + ";; Otwarcie menu attachment C-c C-a \n" + ";; Otwarcie załącznika attachment C-c C-a o \n" + ";; Zapisanie zdjęcia w org C-c o f \n" + ";; Dodanie linku SPC o c \n" + ";; Aby otworzyć ostatnie pliki daj na C-c r\n" + ";; Aby otworzyć treemacs daj na C-c t \n" + ";; Aktywacja środowiska pyenv C-c v a \n" + ";; Eshell C-c e \n" + ";; Pokaż błędy flycheck C-c d \n" + "\n" + ";;Jupyter \n" + ";;Wykonaj Połącz się z serwerem C-c j s \n" + ";;Powiazanie bufora REPL C-c j a \n" + ";;Wykonaj cały bufor C-c j b \n" + ";;Wykkonaj region C-c C-c \n")) +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(custom-safe-themes + '("5a0ddbd75929d24f5ef34944d78789c6c3421aa943c15218bac791c199fc897d" + "d5fd482fcb0fe42e849caba275a01d4925e422963d1cd165565b31d3f4189c87" + "09b833239444ac3230f591e35e3c28a4d78f1556b107bafe0eb32b5977204d93" + default)) + '(package-selected-packages + '(blacken company evil-commentary evil-leader evil-org flycheck + gruvbox-theme jupyter lsp-treemacs lsp-ui magit org-roam + pyvenv scad-mode vterm which-key winum yasnippet-snippets))) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + ) +(put 'narrow-to-region 'disabled nil) + + + +;; ---------------------------- +;; ibuffer +;; ---------------------------- +(with-eval-after-load 'ibuffer + (evil-set-initial-state 'ibuffer-mode 'normal) + + (evil-define-key 'normal ibuffer-mode-map + (kbd "j") 'ibuffer-forward-line + (kbd "k") 'ibuffer-backward-line + (kbd "dd") 'ibuffer-do-kill-lines + (kbd "x") 'ibuffer-do-kill-on-deletion-marks + (kbd "v") 'ibuffer-mark-forward + (kbd "u") 'ibuffer-unmark-forward + (kbd "gg") 'beginning-of-buffer + (kbd "G") 'end-of-buffer + (kbd "/") 'ibuffer-do-isearch + (kbd "q") 'quit-window)) + + + + +;; ---------------------------- +;; Moje makra +;; ---------------------------- + + + + +;; Funkcja tworząca pusty plik .gitignore w Emacs +(defun create-gitignore (directory) + "Tworzy pusty plik .gitignore w podanym katalogu DIRECTORY." + (interactive "DChoose directory: ") + (let ((gitignore-path (expand-file-name ".gitignore" directory))) + (if (file-exists-p gitignore-path) + (message "Plik .gitignore już istnieje w katalogu %s" directory) + (with-temp-file gitignore-path + (insert "")) + (message "Pusty plik .gitignore został utworzony w katalogu %s" directory)))) + +;; Aby użyć tej funkcji, wpisz M-x create-gitignore i wskaż katalog, w którym ma być utworzony pusty plik. + + +(setq select-enable-clipboard t) +(with-eval-after-load 'evil + (define-key evil-insert-state-map (kbd "C-v") 'yank)) + + +(add-hook 'prog-mode-hook #'hs-minor-mode) + +;; Skróty: +(define-key prog-mode-map (kbd "C-c h h") 'hs-hide-block) +(define-key prog-mode-map (kbd "C-c h s") 'hs-show-block) +(define-key prog-mode-map (kbd "C-c h H") 'hs-hide-all) +(define-key prog-mode-map (kbd "C-c h S") 'hs-show-all) + + +