921 lines
30 KiB
EmacsLisp
921 lines
30 KiB
EmacsLisp
;; ----------------------------
|
|
;; Podstawowa konfiguracja pakietów i MELPA
|
|
;; ----------------------------
|
|
(require 'package)
|
|
|
|
;; 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))))
|
|
|
|
|
|
(cond
|
|
((eq system-type 'windows-nt)
|
|
;; Konfiguracja dla Windows
|
|
(setq browse-url-browser-function 'browse-url-firefox)
|
|
(setq browse-url-firefox-program "C:/Program Files/Mozilla Firefox/firefox.exe"))
|
|
((eq system-type 'gnu/linux)
|
|
;; Konfiguracja dla Linux
|
|
(setq browse-url-browser-function 'browse-url-firefox)))
|
|
|
|
|
|
|
|
;; 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)
|
|
|
|
|
|
(require 'scad-mode)
|
|
(add-to-list 'auto-mode-alist '("\\.scad\\'" . scad-mode))
|
|
(defun scad-preview ()
|
|
"Render OpenSCAD file using the openscad command."
|
|
(interactive)
|
|
(let ((file-name (buffer-file-name)))
|
|
(if file-name
|
|
(start-process "openscad" "*OpenSCAD*" "openscad" file-name)
|
|
(message "Buffer is not visiting a file"))))
|
|
|
|
(define-key scad-mode-map (kbd "C-c C-r") 'scad-preview)
|
|
|
|
|
|
;; 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)
|
|
|
|
|
|
|
|
(defun save-image-from-clipboard ()
|
|
"Save an image from clipboard as a PNG file, scale it, and insert a link in Org Mode."
|
|
(interactive)
|
|
(let* ((dir (if (eq system-type 'windows-nt)
|
|
"C:/Users/paluc/Nextcloud/org_images/" ;; Katalog dla Windows
|
|
"~/Nextcloud/org_images/")) ;; Katalog dla Linux
|
|
(system-type-command
|
|
(if (eq system-type 'windows-nt)
|
|
;; Polecenie dla Windows
|
|
"powershell -Command \"Add-Type -AssemblyName System.Drawing; Add-Type -AssemblyName System.Windows.Forms; $image = [System.Windows.Forms.Clipboard]::GetImage(); if ($image -ne $null) { $image.Save('%s', [System.Drawing.Imaging.ImageFormat]::Png) } else { exit 1 }\""
|
|
;; Polecenie dla Linux
|
|
"xclip -selection clipboard -t image/png -o > %s"))
|
|
(filename (generate-unique-filename dir "image" "png")) ;; Automatyczna nazwa
|
|
(file-path (concat (file-name-as-directory dir) filename))) ;; Pełna ścieżka
|
|
(make-directory dir :parents) ;; Tworzenie katalogu, jeśli nie istnieje
|
|
(if (eq 0 (call-process-shell-command (format system-type-command file-path)))
|
|
(progn
|
|
(scale-image file-path 400) ;; Skalowanie obrazu do szerokości 400 px
|
|
(insert (format "[[file:%s]]" (convert-path-to-org file-path))) ;; Wstaw link w buforze
|
|
(org-display-inline-images) ;; Wyświetl obraz w buforze Org Mode
|
|
(message "Image saved to: %s" file-path))
|
|
(message "Error: No image in clipboard or unsupported format."))))
|
|
|
|
(defun generate-unique-filename (dir prefix extension)
|
|
"Generate a unique filename in DIR with PREFIX and EXTENSION."
|
|
(let ((counter 1)
|
|
(filename ""))
|
|
(while (progn
|
|
(setq filename (format "%s-%d.%s" prefix counter extension))
|
|
(file-exists-p (concat (file-name-as-directory dir) filename)))
|
|
(setq counter (1+ counter)))
|
|
filename))
|
|
|
|
(defun scale-image (file-path max-width)
|
|
"Scale the image at FILE-PATH to MAX-WIDTH using ImageMagick's convert."
|
|
(call-process-shell-command
|
|
(format "convert %s -resize %d %s" file-path max-width file-path)))
|
|
|
|
(defun convert-path-to-org (path)
|
|
"Convert Windows paths to Org-compatible paths."
|
|
(if (eq system-type 'windows-nt)
|
|
(replace-regexp-in-string "\\\\" "/" path) ;; Zamiana backslash na slash
|
|
path)) ;; Dla Linux nic nie zmieniamy
|
|
|
|
|
|
|
|
|
|
|
|
;; ----------------------------
|
|
;; Podstawowa konfiguracja Org-Roam
|
|
;; ----------------------------
|
|
|
|
;; Definicja ścieżek dla Org-roam
|
|
(setq my-org-roam-windows-path "C:/Users/paluc/Nextcloud/org/roam/")
|
|
(setq my-org-roam-linux-path "~/Nextcloud/org/roam/")
|
|
|
|
(defun my-set-org-roam-directory ()
|
|
"Ustaw katalog Org-roam w zależności od systemu operacyjnego."
|
|
(setq org-roam-directory
|
|
(file-truename
|
|
(if (eq system-type 'windows-nt)
|
|
my-org-roam-windows-path
|
|
my-org-roam-linux-path))))
|
|
|
|
;; Wywołaj funkcję przy starcie Emacs
|
|
(my-set-org-roam-directory)
|
|
|
|
;; Konfiguracja Org-roam
|
|
(use-package org-roam
|
|
:ensure t
|
|
:bind (("C-c n l" . org-roam-buffer-toggle) ;; Bufor backlinków
|
|
("C-c n f" . org-roam-node-find) ;; Wyszukiwanie notatek
|
|
("C-c n g" . org-roam-graph) ;; Graf powiązań
|
|
("C-c n c" . org-roam-capture)) ;; Tworzenie nowej notatki
|
|
:config
|
|
(org-roam-db-autosync-mode)) ;; Automatyczna synchronizacja bazy danych
|
|
;; Ścieżka do programu "dot" (Graphviz)
|
|
(setq org-roam-graph-executable "dot")
|
|
|
|
;; Format pliku wyjściowego
|
|
(setq org-roam-graph-output "png") ;; Możliwe opcje: "svg", "png", "pdf"
|
|
|
|
;; Dodatkowe opcje dla generowanego grafu
|
|
(setq org-roam-graph-extra-config
|
|
'(("overlap" . "scale") ;; Unikaj nakładania się węzłów
|
|
("splines" . "true") ;; Pokaż linie jako krzywe
|
|
("sep" . "25"))) ;; Odstępy między węzłami
|
|
(setq org-roam-graph-file
|
|
(expand-file-name "org-roam-graph.png" org-roam-directory))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; ----------------------------
|
|
;; 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
|
|
|
|
|
|
;; ----------------------------
|
|
;; Konfiguracja org-mode
|
|
;; ----------------------------
|
|
|
|
|
|
(with-eval-after-load 'org
|
|
(evil-define-key 'normal org-mode-map
|
|
(kbd "L") 'org-do-demote
|
|
(kbd "H") 'org-do-promote))
|
|
|
|
|
|
|
|
(setq org-file-apps
|
|
`((auto-mode . emacs)
|
|
("\\.pdf\\'" . ,(if (eq system-type 'windows-nt)
|
|
"C:/Users/paluc/AppData/Local/SumatraPDF/SumatraPDF.exe %s"
|
|
"xdg-open %s"))))
|
|
|
|
;; Automatyczne generowanie linku
|
|
(setq org-attach-directory "files")
|
|
(setq org-attach-automatic-link t)
|
|
;; Definicja ścieżek dla Windows i Linux
|
|
(setq my-org-agenda-windows-path "C:/Users/paluc/Nextcloud/org/")
|
|
(setq my-org-agenda-linux-path "~/Nextcloud/org/")
|
|
|
|
;; Definicja ścieżek do pliku todo.org
|
|
(setq my-todo-file-windows "C:/Users/paluc/Nextcloud/org/todo.org")
|
|
(setq my-todo-file-linux "~/Nextcloud/org/todo.org")
|
|
(setq my-note-file-windows "C:/Users/paluc/Nextcloud/org/other.org")
|
|
(setq my-note-file-linux "~/Nextcloud/org/other.org")
|
|
|
|
;; Funkcja ustawiająca odpowiednią ścieżkę na podstawie systemu
|
|
(defun my-set-org-agenda-files ()
|
|
"Ustaw pliki agendy Org w zależności od systemu operacyjnego."
|
|
(setq org-agenda-files
|
|
(directory-files-recursively
|
|
(if (eq system-type 'windows-nt)
|
|
my-org-agenda-windows-path
|
|
my-org-agenda-linux-path)
|
|
"\\.org$")))
|
|
|
|
;; Wywołaj funkcję przy starcie Emacs
|
|
(my-set-org-agenda-files)
|
|
|
|
;; Funkcja otwierająca plik todo.org
|
|
(defun my-open-todo-file ()
|
|
"Otwórz plik todo.org w zależności od systemu operacyjnego."
|
|
(interactive)
|
|
(let ((note-file (if (eq system-type 'windows-nt)
|
|
my-todo-file-windows
|
|
my-todo-file-linux)))
|
|
(if (file-exists-p note-file)
|
|
(find-file note-file)
|
|
(message "Plik todo.org nie istnieje: %s" note-file))))
|
|
|
|
|
|
(defun my-open-note-file ()
|
|
"Otwórz plik todo.org w zależności od systemu operacyjnego."
|
|
(interactive)
|
|
(let ((todo-file (if (eq system-type 'windows-nt)
|
|
my-note-file-windows
|
|
my-note-file-linux)))
|
|
(if (file-exists-p todo-file)
|
|
(find-file todo-file)
|
|
(message "Plik todo.org nie istnieje: %s" todo-file))))
|
|
|
|
|
|
|
|
;; Włącz org-mode automatycznie dla plików .org
|
|
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
|
|
|
|
;; Włącz folding w org-mode (skróty klawiszowe)
|
|
(setq org-startup-folded t) ;; Start with folded headlines
|
|
(setq org-hide-leading-stars t) ;; Ukrywanie gwiazdek poza pierwszym poziomem
|
|
(setq org-ellipsis "⤵") ;; Znak na końcu zwiniętych sekcji
|
|
|
|
|
|
;; Ustawienia klawisza TAB w org-mode przy użyciu Evil
|
|
(add-hook 'org-mode-hook
|
|
(lambda ()
|
|
(evil-define-key 'normal org-mode-map (kbd "TAB") 'org-cycle)
|
|
(evil-define-key 'normal org-mode-map (kbd "S-TAB") 'org-shifttab)))
|
|
|
|
|
|
;; Podświetlanie składni i elementów w org-mode
|
|
(setq org-fontify-whole-heading-line t) ;; Podświetlaj cały nagłówek
|
|
(setq org-fontify-done-headline t) ;; Podświetlaj ukończone nagłówki
|
|
(setq org-fontify-quote-and-verse-blocks t) ;; Podświetlaj bloki cytatów i wierszy
|
|
|
|
;; Automatyczne podświetlanie kodu w blokach źródłowych
|
|
(setq org-src-fontify-natively t)
|
|
(setq org-src-tab-acts-natively t)
|
|
|
|
;; Wsparcie dla hierarchicznego folding w org-mode
|
|
(setq org-cycle-separator-lines 2) ;; Próg zwijania między sekcjami
|
|
|
|
;; Wygląd i czytelność w org-mode
|
|
(setq org-hide-emphasis-markers t) ;; Ukryj znaki formatowania (*bold*, /italic/)
|
|
(setq org-pretty-entities t) ;; Wyświetl symbole matematyczne jako unicode
|
|
(setq org-highlight-latex-and-related '(latex script entities)) ;; Podświetlaj LaTeX
|
|
|
|
;; Współpraca z tytułami i nagłówkami
|
|
(setq org-startup-indented t) ;; Włącz automatyczne wcięcia
|
|
(setq org-indent-mode-turns-on-hiding-stars t) ;; Ukryj gwiazdki w nagłówkach
|
|
|
|
;; Funkcje dodatkowe
|
|
(setq org-log-done 'time) ;; Zapisuj czas oznaczenia zadania jako DONE
|
|
(setq org-return-follows-link t) ;; ENTER podąża za linkami
|
|
|
|
|
|
|
|
;; ----------------------------
|
|
;; 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))
|
|
|
|
|
|
|
|
|
|
|
|
;; (defun my-assign-window-numbers ()
|
|
;; "Przypisuje numer do każdego widocznego okna w bieżącej ramce."
|
|
;; (let ((i 1))
|
|
;; (dolist (win (window-list nil 'nomini))
|
|
;; (set-window-parameter win 'my-window-number i)
|
|
;; (setq i (1+ i)))))
|
|
|
|
;; (add-hook 'window-configuration-change-hook #'my-assign-window-numbers)
|
|
;; (add-hook 'buffer-list-update-hook #'my-assign-window-numbers)
|
|
|
|
;; (defun my-get-window-number ()
|
|
;; "Zwraca przypisany numer aktualnego okna."
|
|
;; (let ((num (window-parameter (selected-window) 'my-window-number)))
|
|
;; (propertize (format " #%d " (or num 1))
|
|
;; 'face '(:foreground "yellow" :weight bold))))
|
|
|
|
|
|
|
|
|
|
;; ----------------------------
|
|
;; 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 "<SPC>")
|
|
(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
|
|
"m b" 'build123d
|
|
"m v" 'vosk-start
|
|
"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
|
|
"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
|
|
"<SPC> e" "Errors"
|
|
"<SPC> n" "Narrow"
|
|
"<SPC> f" "Files"
|
|
"<SPC> b" "Buffers"
|
|
"<SPC> r" "Roam"
|
|
"<SPC> t" "Treemacs"
|
|
"<SPC> l" "Lines"
|
|
"<SPC> j" "Jupyter"
|
|
"<SPC> s" "Search&Replace"
|
|
"<SPC> o" "Org"
|
|
"<SPC> m" "Macro"
|
|
"<SPC> 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)
|
|
(scroll-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
|
|
'("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
|
|
;; ----------------------------
|
|
|
|
|
|
(defun vosk-start ()
|
|
"Start Vosk script in the appropriate environment."
|
|
(interactive)
|
|
(let ((file-path (if (eq system-type 'windows-nt)
|
|
"C:/Users/paluc/OneDrive/Dokumenty/venv/voskpl.py"
|
|
"~/venv/voskpl.py")))
|
|
;; Przejdź do voskpl.py
|
|
(find-file file-path)
|
|
;; Otwórz eshell i uruchom vosk
|
|
(eshell 100)
|
|
(insert (format "python %s" file-path))
|
|
(eshell-send-input)))
|
|
|
|
|
|
|
|
|
|
(defun build123d ()
|
|
"Automatyzacja workflow: uruchomienie Jupyter Lab, OCP VSCode i konfiguracja REPL."
|
|
(interactive)
|
|
;; Przejdź do pliku simrig.py
|
|
(let ((file-path (if (eq system-type 'windows-nt)
|
|
;; "C:/Users/paluc/OneDrive/Dokumenty/simrig2/simrig.py"
|
|
;; "C:/Users/paluc/OneDrive/Dokumenty/frezarka/frezarka.py"
|
|
"C:/Users/paluc/OneDrive/Dokumenty/Box_Arduino_Adrian/box.py"
|
|
;; "C:/Users/paluc/OneDrive/Dokumenty/uchwytBaterii/uchwyt.py"
|
|
;; "/home/pali112/Dokumenty/simrig2/simrig.py"
|
|
;; "/home/pali112/Dokumenty/Uchwyt_Myszki/uchwyt.py"
|
|
;; "/home/pali112/Dokumenty/Box_Adriana/box.py"
|
|
;; "/home/pali112/Dokumenty/Box_Arduino_Adrian/box.py"
|
|
"/home/pali112/Dokumenty/buildtraing/bracket2.py"
|
|
;; "/home/pali112/Dokumenty/ipadFreecad/ipad.py"
|
|
;; "/home/pali112/Dokumenty/uchwyt_baterii/uchwyt.py"
|
|
|
|
)))
|
|
|
|
|
|
(find-file file-path)
|
|
;; Otwórz eshell 1 i uruchom Jupyter Lab
|
|
(let ((eshell-buffer-name "*eshell-1*"))
|
|
(eshell 1))
|
|
(sleep-for 1) ;; Czekaj na aktywację pipenv shell
|
|
(evil-insert-state)
|
|
(insert "jupyter lab")
|
|
(eshell-send-input)
|
|
(sleep-for 1) ;; Czekaj na aktywację pipenv shell
|
|
;; Przejdź do eshell 2 i uruchom Python -m ocp_vscode
|
|
(let ((eshell-buffer-name "*eshell-2*"))
|
|
(eshell))
|
|
(sleep-for 1) ;; Czekaj na aktywację pipenv shell
|
|
(evil-insert-state)
|
|
(insert "python -m ocp_vscode")
|
|
(eshell-send-input)
|
|
(sleep-for 1) ;; Czekaj na aktywację pipenv shell
|
|
;; Powróć do pliku simrig.py
|
|
(find-file file-path)
|
|
;; Uruchom jupyter-run-server-repl i pozwól użytkownikowi potwierdzić wartości interaktywnie
|
|
(call-interactively 'jupyter-run-server-repl)
|
|
(sleep-for 1) ;; Czekaj na aktywację pipenv shell
|
|
(find-file file-path)
|
|
(call-interactively 'jupyter-repl-associate-buffer)
|
|
;; Otwórz stronę w przeglądarce
|
|
(browse-url "http://localhost:3939/viewer")))
|
|
|
|
|
|
|
|
(defun remote-nadpisz ()
|
|
"Fetch changes from remote, reset local branch, and clean untracked files."
|
|
(interactive)
|
|
(let ((eshell-buffer (generate-new-buffer "*eshell*")))
|
|
(with-current-buffer eshell-buffer
|
|
(eshell-mode)
|
|
(goto-char (point-max))
|
|
(insert "git fetch --all && git reset --hard origin/master && git clean -fd")
|
|
(eshell-send-input) ;; Wykonuje komendę
|
|
(insert "exit")
|
|
(eshell-send-input))
|
|
(switch-to-buffer eshell-buffer))) ;; Przełącza się do nowego
|
|
|
|
|
|
|
|
|
|
;; 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)
|
|
|
|
|
|
|