Alcuni dei keybinds che uso
(global-set-key (kbd "C-=") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
(global-set-key (kbd "C-h C-l") 'find-library)
(global-set-key (kbd "C-h M-h") 'remove-hook)
(global-set-key (kbd "C-h C-b") 'button-describe)
(global-set-key (kbd "C-h C-v") 'set-variable)
(global-set-key (kbd "C-x C-g") 'find-grep)
(global-set-key (kbd "C-c p") 'beginning-of-buffer)
(global-set-key (kbd "C-c n") 'end-of-buffer)
(global-set-key (kbd "C-t") #'transpose-words)
(global-set-key (kbd "M-t") #'transpose-chars)
(global-set-key (kbd "C-S-d") 'kill-word)
(global-set-key (kbd "C-S-o") 'duplicate-line)
(global-set-key (kbd "C-S-w") 'mark-word)
(global-set-key (kbd "C-c C-p") 'laluxx/find-package-source-code)
(global-set-key (kbd "C-x C-r") 'consult-recent-file)
(global-set-key (kbd "C-h C-f") 'describe-face)
(global-set-key (kbd "C-h t") 'consult-theme)
(global-set-key (kbd "C-x k") 'kill-current-buffer)
(global-set-key (kbd "C-c i") 'consult-imenu)
(global-set-key (kbd "C-x f") 'consult-find)
(global-set-key (kbd "M-n") 'forward-paragraph)
(global-set-key (kbd "M-p") 'backward-paragraph)
(global-set-key (kbd "C-h C-e") #'consult-flycheck)
(defun laluxx/mwim-beginning-of-line ()
"Move to beginning of line or string intelligently.
If inside a string:
- First call moves to beginning of string content
- Second call moves to beginning of line
If not in string, moves to beginning of line."
(interactive)
(let ((string-bounds (laluxx/mwim--in-string-p))
(orig-point (point)))
(if (not string-bounds)
(beginning-of-line)
(if (= (point) (car string-bounds))
(beginning-of-line)
(goto-char (car string-bounds))))))
(defun laluxx/mwim-end-of-line ()
"Move to end of line or string intelligently.
If inside a string:
- First call moves to end of string content
- Second call moves to end of line
If not in string, moves to end of line."
(interactive)
(let ((string-bounds (laluxx/mwim--in-string-p))
(orig-point (point)))
(if (not string-bounds)
(end-of-line)
(if (= (point) (cdr string-bounds))
(end-of-line)
(goto-char (cdr string-bounds))))))
(global-set-key (kbd "C-a") #'laluxx/mwim-beginning-of-line)
(global-set-key (kbd "C-e") #'laluxx/mwim-end-of-line)
(defun laluxx/dired-jump-or-kill ()
"Jump to Dired buffer in another window or kill the Dired buffer if already in one."
(interactive)
(if (eq major-mode 'dired-mode)
(progn
(kill-this-buffer)
(delete-window))
(dired-jump-other-window)))
(global-set-key (kbd "C-x C-l") 'laluxx/dired-jump-or-kill)
(global-set-key (kbd "C-h C-s") 'eww)
(global-set-key (kbd "C-h g") #'magit-status)
(global-set-key (kbd "C-h C-c") #'magit-log-all)
(defun laluxx/toggle-ielm ()
"Toggle ielm buffer."
(interactive)
(toggle-buffer "*ielm*" #'ielm))
(global-set-key (kbd "C-c C-i") 'laluxx/toggle-ielm)
(global-set-key (kbd "C-h w") 'woman)
(defun laluxx/delete-blank-lines ()
(interactive)
(delete-blank-lines)
(open-line 1)
(next-line 1)
(open-line 1))
(global-set-key (kbd "C-x C-o") 'laluxx/delete-blank-lines)
(defun laluxx/adjust-hex-color (hex-string delta)
"Adjust each RGB component of HEX-STRING by DELTA."
(let* ((rgb-str (substring hex-string 1)) ; Remove # prefix
(rgb-val (string-to-number rgb-str 16))
(r (lsh rgb-val -16))
(g (logand (lsh rgb-val -8) #xFF))
(b (logand rgb-val #xFF))
(new-r (min 255 (max 0 (+ r delta))))
(new-g (min 255 (max 0 (+ g delta))))
(new-b (min 255 (max 0 (+ b delta)))))
(format "#%02x%02x%02x" new-r new-g new-b)))
;; NOTE Useful for macros
(defun laluxx/smart-increment-at-point (&optional n)
"Increment number or adjust hex color at point by N (default 1)."
(interactive "p")
(or n (setq n 1))
(save-excursion
(skip-chars-backward "0123456789abcdefABCDEF#")
(cond
;; Hex color case
((looking-at "#[0-9a-fA-F]\\{6\\}")
(let* ((hex-color (match-string 0))
(new-color (laluxx/adjust-hex-color hex-color n)))
(replace-match new-color)))
;; Number case
((looking-at "[0-9]+")
(replace-match
(number-to-string (+ (string-to-number (match-string 0)) n))))
(t (error "No number or hex color at point")))))
(defun laluxx/smart-decrement-at-point (&optional n)
"Decrement number or adjust hex color at point by N (default 1)."
(interactive "p")
(laluxx/smart-increment-at-point (- (or n 1))))
;; Key bindings
(global-set-key (kbd "<XF86AudioRaiseVolume>") 'laluxx/smart-increment-at-point)