emacs/common/generic_functions.el

103 lines
3.7 KiB
EmacsLisp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; generic functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; open org agenda in top side window
(defun kmn/org-agenda-on-top ()
(defvar parameters
'(window-parameters . ((no-other-window . t)
(no-delete-other-windows . t))))
(setq fit-window-to-buffer-horizontally t)
(setq window-resize-pixelwise t)
(interactive)
(display-buffer-in-side-window
(get-buffer "*Org Agenda*") `((side . top) (slot . 0)
(window-width . fit-window-to-buffer)
(preserve-size . (t . nil)) , parameters))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; open dired with default directory in left side window
(defun kmn/dired-default-directory-on-left ()
(defvar parameters
'(window-parameters . ((no-other-window . t)
(no-delete-other-windows . t))))
(setq fit-window-to-buffer-horizontally t)
(setq window-resize-pixelwise t)
"Display `default-directory' in side window on left, hiding details."
(interactive)
(let ((buffer (dired-noselect default-directory)))
(with-current-buffer buffer (dired-hide-details-mode t))
(display-buffer-in-side-window
buffer `((side . left) (slot . -1)
(window-width . fit-window-to-buffer)
(preserve-size . (t . nil)) , parameters)
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; quick reference notes as a pop up window
(defun kmn/popwin-quick-ref ()
(interactive)
(when (eq system-type 'windows-nt)
(popwin:find-file "~/org/_quick_reference.org"))
(when kmn/is-termux
(popwin:find-file "~/storage/shared/org/_quick_reference.org")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; scratch buffer as a pop up window
(defun kmn/popwin-scratch ()
(interactive)
(popwin:display-buffer "*scratch*")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; modern home/end via C-a and C-e
(defun kmn/smart-beginning-of-line ()
"Move point to `beginning-of-line'. If repeat command it cycle
position between `back-to-indentation' and `beginning-of-line'."
(interactive "^")
(if (eq last-command 'my--smart-beginning-of-line)
(if (= (line-beginning-position) (point))
(back-to-indentation)
(beginning-of-line))
(back-to-indentation)))
(defun kmn/smart-end-of-line ()
"Move point to `end-of-line'. If repeat command it cycle
position between last non-whitespace and `end-of-line'."
(interactive "^")
(if (and (eq last-command 'kmn/my--smart-end-of-line)
(= (line-end-position) (point)))
(skip-syntax-backward " " (line-beginning-position))
(end-of-line)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; function to kill all non special, non active buffers
(defun kmn/kill-other-buffers ()
"Kill all buffers but the current one. Don't mess with special buffers."
(interactive)
(dolist (buffer (buffer-list))
(unless (or (eql buffer (current-buffer)) (not (buffer-file-name buffer)))
(kill-buffer buffer))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; find/replace all (interactive)
(defun kmn/query-replace-region-or-from-top ()
"If marked, query-replace for the region, else for the whole buffer (start from the top)"
(interactive)
(progn
(let ((orig-point (point)))
(if (use-region-p)
(call-interactively 'query-replace)
(save-excursion
(goto-char (point-min))
(call-interactively 'query-replace)))
(message "Back to old point.")
(goto-char orig-point))))