Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
d0d69cb31a | |||
18d06a4aea | |||
e23fb67b30 | |||
f724ba27c7 | |||
3d4e9a0ecf | |||
ae782630e5 | |||
f1592e491a | |||
42fa510428 | |||
91404b3196 | |||
1cadc1fd67 | |||
395504b1ea | |||
8a6353b2c5 | |||
a5d503f1a6 | |||
9e5528e519 | |||
69549ce861 | |||
3bd5c2c865 | |||
7502d37992 | |||
2cb666aa7b | |||
47930acec4 | |||
5d89b6dd23 | |||
dd17f2dcc7 |
3145
configuration.org
3145
configuration.org
File diff suppressed because it is too large
Load Diff
65
lisp/gpolonkai/file-utils.el
Normal file
65
lisp/gpolonkai/file-utils.el
Normal file
@ -0,0 +1,65 @@
|
||||
;;; gpolonkai/file-utils.el --- File manipulation utilities
|
||||
;;;
|
||||
;;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||
;;; Copyright © 2025 Gergely Polonkai
|
||||
;;; This library is free software; you can redistribute it and/or
|
||||
;;; modify it under the terms of the GNU Lesser General Public
|
||||
;;; License as published by the Free Software Foundation; either
|
||||
;;; version 3 of the License, or (at your option) any later version.
|
||||
;;;
|
||||
;;; This library is distributed in the hope that it will be useful,
|
||||
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;;; Lesser General Public License for more details.
|
||||
;;;
|
||||
;;; You should have received a copy of the GNU Lesser General Public
|
||||
;;; License along with this library; if not, write to the
|
||||
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
;;; Boston, MA 02111-1307, USA.
|
||||
;;;
|
||||
;;; Commentary:
|
||||
;;;
|
||||
;;; Utility functions stolen from the Internet or written by me
|
||||
;;;
|
||||
;;; Code:
|
||||
|
||||
;; From whattheemacsd.org: http://whattheemacsd.com/file-defuns.el-01.html
|
||||
|
||||
(defun wted/rename-current-buffer-file ()
|
||||
"Renames current buffer and the file it is visiting."
|
||||
(interactive)
|
||||
|
||||
(let ((name (buffer-name))
|
||||
(filename (buffer-file-name)))
|
||||
(if (not (and filename (file-exists-p filename)))
|
||||
(error "Buffer '%s' is not visiting a file!" name)
|
||||
(let ((new-name (read-file-name "New name: " filename)))
|
||||
(if (get-buffer new-name)
|
||||
(error "A buffer named '%s' already exists!" new-name)
|
||||
(rename-file filename new-name 1)
|
||||
(rename-buffer new-name)
|
||||
(set-visited-file-name new-name)
|
||||
; TODO: this is suspicious for me…
|
||||
(set-buffer-modified-p nil)
|
||||
(message "File '%s' successfully renamed to '%s'"
|
||||
name (file-name-nondirectory new-name)))))))
|
||||
|
||||
;; From whattheemacsd.org: http://whattheemacsd.com/file-defuns.el-02.html
|
||||
|
||||
(defun wted/delete-current-buffer-file ()
|
||||
"Remove file the current buffer is visiting and kill the buffer."
|
||||
(interactive)
|
||||
|
||||
(let ((filename (buffer-file-name))
|
||||
(name (buffer-name))
|
||||
(buffer (current-buffer)))
|
||||
(if (not (and filename (file-exists-p filename)))
|
||||
(kill-buffer buffer)
|
||||
(when (yes-or-no-p "Are you sure you want to remove this file? ")
|
||||
(delete-file filename)
|
||||
(kill-buffer buffer)
|
||||
(message "File '%s' successfully removed" filename)))))
|
||||
|
||||
(provide 'gpolonkai/file-utils)
|
||||
|
||||
;;; file-utils.el ends here
|
65
lisp/gpolonkai/magit-utils.el
Normal file
65
lisp/gpolonkai/magit-utils.el
Normal file
@ -0,0 +1,65 @@
|
||||
;;; gpolonkai/magit-utils.el --- Magit related utilities
|
||||
;;;
|
||||
;;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||
;;; Copyright © 2025 Gergely Polonkai
|
||||
;;; This library is free software; you can redistribute it and/or
|
||||
;;; modify it under the terms of the GNU Lesser General Public
|
||||
;;; License as published by the Free Software Foundation; either
|
||||
;;; version 3 of the License, or (at your option) any later version.
|
||||
;;;
|
||||
;;; This library is distributed in the hope that it will be useful,
|
||||
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;;; Lesser General Public License for more details.
|
||||
;;;
|
||||
;;; You should have received a copy of the GNU Lesser General Public
|
||||
;;; License along with this library; if not, write to the
|
||||
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
;;; Boston, MA 02111-1307, USA.
|
||||
;;;
|
||||
;;; Commentary:
|
||||
;;;
|
||||
;;; Utility functions stolen from the Internet or written by me
|
||||
;;;
|
||||
;;; Code:
|
||||
|
||||
(defun gpolonkai/magit-goto-beginning-of-section ()
|
||||
"Go to the beginning of the current Magit section."
|
||||
(interactive)
|
||||
(let ((section (magit-current-section)))
|
||||
(magit-section-goto section)))
|
||||
|
||||
(defun gpolonkai/magit-goto-end-of-section ()
|
||||
"Move to the beginning of the next visible section."
|
||||
(interactive)
|
||||
(unless (eobp)
|
||||
(let ((section (magit-current-section)))
|
||||
(if (oref section parent)
|
||||
(let ((next (and (not (oref section hidden))
|
||||
(not (= (oref section end)
|
||||
(1+ (point))))
|
||||
(car (oref section children)))))
|
||||
(while (and section (not next))
|
||||
(unless (setq next (car (magit-section-siblings section 'next)))
|
||||
(setq section (oref section parent))))
|
||||
(if next
|
||||
(magit-section-goto next)
|
||||
(end-of-buffer)))
|
||||
(magit-section-goto 1)))))
|
||||
|
||||
(defun gpolonkai/magit-find-first-link ()
|
||||
"Find the first URL in the current section."
|
||||
(interactive)
|
||||
(let ((bos (save-excursion
|
||||
(gpolonkai/magit-goto-beginning-of-section)
|
||||
(point)))
|
||||
(eos (save-excursion
|
||||
(gpolonkai/magit-goto-end-of-section)
|
||||
(point))))
|
||||
(goto-char bos)
|
||||
(when (re-search-forward "https?://" eos t)
|
||||
(goto-char (match-beginning 0)))))
|
||||
|
||||
(provide 'gpolonkai/magit-utils)
|
||||
|
||||
;;; magit-utils.el ends here
|
88
lisp/gpolonkai/nav-utils.el
Normal file
88
lisp/gpolonkai/nav-utils.el
Normal file
@ -0,0 +1,88 @@
|
||||
;;; gpolonkai/nav-utils.el --- Navigation utilities
|
||||
;;;
|
||||
;;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||
;;; Copyright © 2025 Gergely Polonkai
|
||||
;;; This library is free software; you can redistribute it and/or
|
||||
;;; modify it under the terms of the GNU Lesser General Public
|
||||
;;; License as published by the Free Software Foundation; either
|
||||
;;; version 3 of the License, or (at your option) any later version.
|
||||
;;;
|
||||
;;; This library is distributed in the hope that it will be useful,
|
||||
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;;; Lesser General Public License for more details.
|
||||
;;;
|
||||
;;; You should have received a copy of the GNU Lesser General Public
|
||||
;;; License along with this library; if not, write to the
|
||||
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
;;; Boston, MA 02111-1307, USA.
|
||||
;;;
|
||||
;;; Commentary:
|
||||
;;;
|
||||
;;; Utility functions stolen from the Internet or written by me
|
||||
;;;
|
||||
;;; Code:
|
||||
|
||||
;; Inspired by Bozhidar Batsov's solution:
|
||||
;; http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/
|
||||
|
||||
(defun gpolonkai/move-to-beginning-of-line ()
|
||||
"Move to different beginnings of the line.
|
||||
|
||||
These are, in order:
|
||||
|
||||
- beginning of the visual line if `visual-line-mode' is active,
|
||||
- the first non-whitespace (indentation),
|
||||
- the actual beginning of the line.
|
||||
|
||||
This function will jump between the first character and the
|
||||
indentation if used multiple times."
|
||||
(interactive)
|
||||
(let ((last-pos (point)))
|
||||
(when visual-line-mode
|
||||
(beginning-of-visual-line))
|
||||
(when (= (point) last-pos)
|
||||
(back-to-indentation))
|
||||
(when (= (point) last-pos)
|
||||
(beginning-of-line))
|
||||
(when (and (eq major-mode 'org-mode)
|
||||
(= (point) last-pos))
|
||||
(org-beginning-of-line))
|
||||
(when (= (point) last-pos)
|
||||
(back-to-indentation))))
|
||||
|
||||
(defun gpolonkai/move-to-end-of-line ()
|
||||
"Move to the end of the line.
|
||||
|
||||
If `visual-line-mode' is active, jump to the end of the visual
|
||||
line first. Then jump to the actual end of the line."
|
||||
(interactive)
|
||||
(let ((last-pos (point)))
|
||||
(when visual-line-mode
|
||||
(end-of-visual-line))
|
||||
(when (= (point) last-pos)
|
||||
(end-of-line))
|
||||
(when (and (eq major-mode 'org-mode)
|
||||
(= (point) last-pos))
|
||||
(org-end-of-line))))
|
||||
|
||||
(defun gpolonkai/goto-next-char (chr)
|
||||
"Move toe the next occurence of CHR on the same line."
|
||||
(interactive "c")
|
||||
(when (search-forward (char-to-string chr) (pos-eol) t)
|
||||
(backward-char)))
|
||||
|
||||
(defun gpolonkai/beginning-of-next-word ()
|
||||
"Move to the beginning of the next word."
|
||||
(interactive)
|
||||
(let ((current-point (point)))
|
||||
(forward-word 1)
|
||||
(backward-word 1)
|
||||
|
||||
(when (<= (point) current-point)
|
||||
(forward-word 2)
|
||||
(backward-word 1))))
|
||||
|
||||
(provide 'gpolonkai/nav-utils)
|
||||
|
||||
;;; nav-utils.el ends here
|
175
lisp/gpolonkai/org-utils.el
Normal file
175
lisp/gpolonkai/org-utils.el
Normal file
@ -0,0 +1,175 @@
|
||||
;;; gpolonkai/org-utils.el --- Org-mode related functions
|
||||
;;;
|
||||
;;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||
;;; Copyright © 2025 Gergely Polonkai
|
||||
;;; This library is free software; you can redistribute it and/or
|
||||
;;; modify it under the terms of the GNU Lesser General Public
|
||||
;;; License as published by the Free Software Foundation; either
|
||||
;;; version 3 of the License, or (at your option) any later version.
|
||||
;;;
|
||||
;;; This library is distributed in the hope that it will be useful,
|
||||
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;;; Lesser General Public License for more details.
|
||||
;;;
|
||||
;;; You should have received a copy of the GNU Lesser General Public
|
||||
;;; License along with this library; if not, write to the
|
||||
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
;;; Boston, MA 02111-1307, USA.
|
||||
;;;
|
||||
;;; Commentary:
|
||||
;;;
|
||||
;;; Utility functions stolen from the Internet or written by me
|
||||
;;;
|
||||
;;; Code:
|
||||
|
||||
(defun gpolonkai/org-agenda-list (&optional arg)
|
||||
"Wrapper around `org-agenda' to open my custom list.
|
||||
|
||||
ARG is passed verbatim to `org-agenda'."
|
||||
(interactive "P")
|
||||
(org-agenda arg "c"))
|
||||
|
||||
(defun gpolonkai/org-insert-current-timestamp (&optional arg)
|
||||
"Insert the current timestamp.
|
||||
|
||||
ARG is passed verbatim to `org-time-stamp'."
|
||||
(interactive "P")
|
||||
(org-time-stamp '(16) arg))
|
||||
|
||||
(defcustom gpolonkai/org-dbl-space-punct-marks (list ?. ?! ?? ?…)
|
||||
"Punctuation marks after which the space key should insert two space characters."
|
||||
:type '(set character))
|
||||
|
||||
(defun gpolonkai/org-space-key (&optional arg)
|
||||
"Insert two spaces after certain markers.
|
||||
|
||||
ARG will be passed down verbatim to `self-insert-command'."
|
||||
(interactive "p")
|
||||
|
||||
(when (and
|
||||
(not (org-in-block-p '("src")))
|
||||
(looking-back (rx-to-string `(any,@ gpolonkai/org-dbl-space-punct-marks)) nil))
|
||||
(call-interactively 'self-insert-command arg))
|
||||
(call-interactively 'self-insert-command arg))
|
||||
|
||||
;; The whole idea comes from https://blog.aaronbieber.com/2016/09/24/an-agenda-for-life-with-org-mode.html
|
||||
;; which i use almost verbatim, hence the ~air-~ prefix.
|
||||
(defun air-org-skip-subtree-if-priority (priority)
|
||||
"Skip an agenda subtree if it has a priority of PRIORITY.
|
||||
|
||||
PRIORITY may be one of the characters ?A, ?B, or ?C."
|
||||
(let ((subtree-end (save-excursion (org-end-of-subtree t)))
|
||||
(pri-value (* 1000 (- org-lowest-priority priority)))
|
||||
(pri-current (org-get-priority (thing-at-point 'line t))))
|
||||
(if (= pri-value pri-current)
|
||||
subtree-end
|
||||
nil)))
|
||||
|
||||
(defun air-org-skip-subtree-if-habit ()
|
||||
"Skip an agenda entry if it has a STYLE property equal to \"habit\"."
|
||||
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
|
||||
(if (string= (org-entry-get nil "STYLE") "habit")
|
||||
subtree-end
|
||||
nil)))
|
||||
|
||||
(defun gpolonkai/org-skip-subtree-if-state (state)
|
||||
"Skip an agenda entry if its state is STATE."
|
||||
(let ((subtree-end (save-excursion (org-end-of-subtree t))))
|
||||
(if (string= (org-get-todo-state) state)
|
||||
subtree-end
|
||||
nil)))
|
||||
|
||||
(defun gpolonkai/org-insert-heading-created (&optional arg)
|
||||
"Insert a heading with the CREATED property set to the current time.
|
||||
|
||||
This emulates how Orgzly works.
|
||||
|
||||
If ARG is set, insert a subheading; otherwise insert a heading."
|
||||
(interactive "p")
|
||||
(let* ((org-insert-heading-respect-content t)
|
||||
(format-string (concat "[" (substring (cdr org-time-stamp-formats) 1 -1) "]"))
|
||||
(timestamp (format-time-string format-string (current-time))))
|
||||
(if (> arg 1)
|
||||
(org-insert-subheading '(4))
|
||||
(org-insert-heading))
|
||||
(org-set-property "CREATED" timestamp)))
|
||||
|
||||
;; The following functions, prefixed with `f-ediff', are from the org-mode mailing list (see archive
|
||||
;; at https://list.orgmode.org/loom.20130801T011342-572@post.gmane.org/).
|
||||
|
||||
(defun f-ediff-org-showhide (buf command &rest cmdargs)
|
||||
"If buffer BUF exists and in `org-mode', execute COMMAND with CMDARGS."
|
||||
(when buf
|
||||
(when (eq (buffer-local-value 'major-mode (get-buffer buf)) 'org-mode)
|
||||
(save-excursion
|
||||
(set-buffer buf)
|
||||
(apply command cmdargs)))))
|
||||
|
||||
(defun f-ediff-org-unfold-tree-element ()
|
||||
"Unfold tree at diff location."
|
||||
(f-ediff-org-showhide ediff-buffer-A 'org-reveal)
|
||||
(f-ediff-org-showhide ediff-buffer-B 'org-reveal)
|
||||
(f-ediff-org-showhide ediff-buffer-C 'org-reveal))
|
||||
|
||||
(defun f-ediff-org-fold-tree ()
|
||||
"Fold tree back to top level."
|
||||
(f-ediff-org-showhide ediff-buffer-A 'hide-sublevels 1)
|
||||
(f-ediff-org-showhide ediff-buffer-B 'hide-sublevels 1)
|
||||
(f-ediff-org-showhide ediff-buffer-C 'hide-sublevels 1))
|
||||
|
||||
;; From the Howardism blog: http://www.howardism.org/Technical/Emacs/capturing-content.html
|
||||
|
||||
(defun ha/org-capture-fileref-snippet (f type headers func-name)
|
||||
"Capture a snippet from a file, with the filename and the location within.
|
||||
|
||||
F is the name of the file the capture is coming from.
|
||||
|
||||
TYPE is the type of the block to be inserted (e.g. \"src\").
|
||||
|
||||
HEADERS are the headers appended to the block's #begin line (usually starting
|
||||
with the language’s mode).
|
||||
|
||||
FUNC-NAME is the name of the function point is in, if any."
|
||||
(let* ((code-snippet
|
||||
(buffer-substring-no-properties (mark) (- (point) 1)))
|
||||
(file-name (buffer-file-name))
|
||||
(file-base (file-name-nondirectory file-name))
|
||||
(line-number (line-number-at-pos (region-beginning)))
|
||||
(initial-txt (if (null func-name)
|
||||
(format "From [[file:%s::%s][%s]]:"
|
||||
file-name line-number file-base)
|
||||
(format "From ~%s~ (in [[file:%s::%s][%s]]):"
|
||||
func-name file-name line-number
|
||||
file-base))))
|
||||
(format "
|
||||
%s
|
||||
|
||||
,#+begin_%s %s
|
||||
%s
|
||||
,#+end_%s" initial-txt type headers code-snippet type)))
|
||||
|
||||
(defun ha/org-capture-clip-snippet (f)
|
||||
"Capture the selected text as an EXAMPLE block.
|
||||
|
||||
The captured text also contains a backlink to the file.
|
||||
|
||||
F is the file the capture is coming from."
|
||||
(with-current-buffer (find-buffer-visiting f)
|
||||
(ha/org-capture-fileref-snippet f "example" "" nil)))
|
||||
|
||||
(defun ha/org-capture-code-snippet (f)
|
||||
"Capture the selected text as an SRC block.
|
||||
|
||||
The captured block will have the correct language set, and contains a backlink
|
||||
to the file.
|
||||
|
||||
F is the file the capture is coming from."
|
||||
(with-current-buffer (find-buffer-visiting f)
|
||||
(let ((org-src-mode (replace-regexp-in-string "-mode" "" (format "%s" major-mode)))
|
||||
(func-name (which-function)))
|
||||
(ha/org-capture-fileref-snippet f "src" org-src-mode func-name))))
|
||||
|
||||
(provide 'gpolonkai/org-utils)
|
||||
|
||||
;;; org-utils.el ends here
|
136
lisp/gpolonkai/text-utils.el
Normal file
136
lisp/gpolonkai/text-utils.el
Normal file
@ -0,0 +1,136 @@
|
||||
;;; gpolonkai/text-utils.el --- Text manipulation utilities
|
||||
;;;
|
||||
;;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||
;;; Copyright © 2025 Gergely Polonkai
|
||||
;;; This library is free software; you can redistribute it and/or
|
||||
;;; modify it under the terms of the GNU Lesser General Public
|
||||
;;; License as published by the Free Software Foundation; either
|
||||
;;; version 3 of the License, or (at your option) any later version.
|
||||
;;;
|
||||
;;; This library is distributed in the hope that it will be useful,
|
||||
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;;; Lesser General Public License for more details.
|
||||
;;;
|
||||
;;; You should have received a copy of the GNU Lesser General Public
|
||||
;;; License along with this library; if not, write to the
|
||||
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
;;; Boston, MA 02111-1307, USA.
|
||||
;;;
|
||||
;;; Commentary:
|
||||
;;;
|
||||
;;; Utility functions stolen from the Internet or written by me
|
||||
;;;
|
||||
;;; Code:
|
||||
|
||||
;; From Sacha Chua’s blog: http://pages.sachachua.com/.emacs.d/Sacha.html
|
||||
|
||||
(defun sachachua/fill-or-unfill-paragraph (&optional unfill region)
|
||||
"Fill (or unfill, if UNFILL is non-nil) paragraph (or REGION)."
|
||||
(interactive (progn
|
||||
(barf-if-buffer-read-only)
|
||||
(list (if current-prefix-arg 'unfill) t)))
|
||||
(let ((fill-column (if unfill (point-max) fill-column)))
|
||||
(fill-paragraph nil region)))
|
||||
|
||||
;; Based on Xah’s toggle letter case defun (version 2015-12-22):
|
||||
;; http://ergoemacs.org/emacs/modernization_upcase-word.html
|
||||
|
||||
(defun gpolonkai/toggle-char-case (arg-move-point)
|
||||
"Toggle the case of the char after point.
|
||||
|
||||
If prefix argument ARG-MOVE-POINT is non-nil, move point after the char."
|
||||
(interactive "P")
|
||||
(let ((case-fold-search nil))
|
||||
(cond
|
||||
((looking-at "[[:lower:]]") (upcase-region (point) (1+ (point))))
|
||||
((looking-at "[[:upper:]]") (downcase-region (point) (1+ (point)))))
|
||||
(cond
|
||||
(arg-move-point (right-char)))))
|
||||
|
||||
;; The next two functions are from whattheemacsd.com: http://whattheemacsd.com/editing-defuns.el-01.html
|
||||
|
||||
(defun gpolonkai/numeric-sort-lines (reverse beg end)
|
||||
"Sort lines in region by \"version\".
|
||||
|
||||
\"version\" is the first number found on a line.
|
||||
|
||||
If REVERSE is set, sort in reverse order.
|
||||
|
||||
BEG and END are the two ends of the region."
|
||||
(interactive "P\nr")
|
||||
(save-excursion
|
||||
(save-restriction
|
||||
(narrow-to-region beg end)
|
||||
(goto-char (point-min))
|
||||
(let ((indibit-field-text-motion t))
|
||||
(sort-subr reverse 'forward-line 'end-of-line #'gpolonkai/find-number-on-line)))))
|
||||
|
||||
(defun wted/open-line-above ()
|
||||
"Open a new line above point."
|
||||
|
||||
(interactive)
|
||||
(beginning-of-line)
|
||||
(newline)
|
||||
(forward-line -1)
|
||||
(let ((tab-always-indent t)
|
||||
(c-tab-always-indent t))
|
||||
(indent-for-tab-command)))
|
||||
|
||||
(defun wted/open-line-below ()
|
||||
"Open a new line below point."
|
||||
|
||||
(interactive)
|
||||
|
||||
(end-of-line)
|
||||
(newline)
|
||||
(let ((tab-always-indent t)
|
||||
(c-tab-always-indent t))
|
||||
(indent-for-tab-command)))
|
||||
|
||||
;; From Marcin Borkowski’s blog: http://mbork.pl/2019-02-17_Inserting_the_current_file_name_at_point
|
||||
|
||||
(defun mbork/insert-current-file-name-at-point (&optional full-path)
|
||||
"Insert the current filename at point.
|
||||
|
||||
With prefix argument, or with FULL-PATH set to non-nil, use full path of the file."
|
||||
(interactive "P")
|
||||
(let* ((buffer
|
||||
(if (minibufferp)
|
||||
(window-buffer
|
||||
(minibuffer-selected-window))
|
||||
(current-buffer)))
|
||||
(filename (buffer-file-name buffer)))
|
||||
(if filename
|
||||
(insert (if full-path filename (file-name-nondirectory filename)))
|
||||
(error (format "Buffer %s is not visiting a file" (buffer-name buffer))))))
|
||||
|
||||
;; From Emacs SE: http://emacs.stackexchange.com/a/27170/507
|
||||
|
||||
(defun e-se/query-swap-strings (from-string to-string &optional delimited start end)
|
||||
"Swap occurrences of FROM-STRING and TO-STRING.
|
||||
|
||||
DELIMITED, START, and END are passed down verbatim to `perform-replace'."
|
||||
(interactive
|
||||
(let ((common
|
||||
(query-replace-read-args
|
||||
(concat "Query swap"
|
||||
(if current-prefix-arg
|
||||
(if (eq current-prefix-arg '-) " backward" " word")
|
||||
"")
|
||||
(if (use-region-p) " in region" ""))
|
||||
nil)))
|
||||
(list (nth 0 common) (nth 1 common) (nth 2 common)
|
||||
(if (use-region-p) (region-beginning))
|
||||
(if (use-region-p) (region-end)))))
|
||||
(perform-replace
|
||||
(concat "\\(" (regexp-quote from-string) "\\)\\|" (regexp-quote to-string))
|
||||
`(replace-eval-replacement replace-quote
|
||||
(if (match-string 1)
|
||||
,to-string
|
||||
,from-string))
|
||||
t t delimited nil nil start end))
|
||||
|
||||
(provide 'gpolonkai/text-utils)
|
||||
|
||||
;;; text-utils.el ends here
|
86
lisp/gpolonkai/windows.el
Normal file
86
lisp/gpolonkai/windows.el
Normal file
@ -0,0 +1,86 @@
|
||||
;;; gpolonkai/windows.el --- Window manipulation
|
||||
;;;
|
||||
;;; SPDX-License-Identifier: GPL-3.0-or-later
|
||||
;;; Copyright © 2025 Gergely Polonkai
|
||||
;;; This library is free software; you can redistribute it and/or
|
||||
;;; modify it under the terms of the GNU Lesser General Public
|
||||
;;; License as published by the Free Software Foundation; either
|
||||
;;; version 3 of the License, or (at your option) any later version.
|
||||
;;;
|
||||
;;; This library is distributed in the hope that it will be useful,
|
||||
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
;;; Lesser General Public License for more details.
|
||||
;;;
|
||||
;;; You should have received a copy of the GNU Lesser General Public
|
||||
;;; License along with this library; if not, write to the
|
||||
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
;;; Boston, MA 02111-1307, USA.
|
||||
;;;
|
||||
;;; Commentary:
|
||||
;;;
|
||||
;;; Utility functions stolen from the Internet or written by me
|
||||
;;;
|
||||
;;; Code:
|
||||
|
||||
(defun gpolonkai/bury-window (window)
|
||||
"Quit WINDOW without killing it (effectively burying it under other windows)."
|
||||
(interactive)
|
||||
(quit-window nil window))
|
||||
|
||||
(defun gpolonkai/scroll-window-up (window)
|
||||
"Scroll WINDOW up as `scroll-up-command' would."
|
||||
(interactive)
|
||||
(save-selected-window
|
||||
(select-window window)
|
||||
(scroll-up)))
|
||||
|
||||
(defun gpolonkai/scroll-window-down (window)
|
||||
"Scroll WINDOW down as `scroll-down-command' would."
|
||||
(interactive)
|
||||
(save-selected-window
|
||||
(select-window window)
|
||||
(scroll-down)))
|
||||
|
||||
(defun gpolonkai/transpose-windows (arg)
|
||||
"Transpose the buffers shown in two windows."
|
||||
(interactive "p")
|
||||
(let ((selector (if (>= arg 0) 'next-window 'previous-window)))
|
||||
(while (/= arg 0)
|
||||
(let ((this-win (window-buffer))
|
||||
(next-win (window-buffer (funcall selector))))
|
||||
(set-window-buffer (selected-window) next-win)
|
||||
(set-window-buffer (funcall selector) this-win)
|
||||
(select-window (funcall selector)))
|
||||
(setq arg (if (plusp arg) (1- arg) (1+ arg))))))
|
||||
|
||||
(defun gpolonkai/toggle-window-split ()
|
||||
"Toggle window split between horizontal and vertical."
|
||||
(interactive)
|
||||
(if (= (count-windows) 2)
|
||||
(let* ((this-win-buffer (window-buffer))
|
||||
(next-win-buffer (window-buffer (next-window)))
|
||||
(this-win-edges (window-edges (selected-window)))
|
||||
(next-win-edges (window-edges (next-window)))
|
||||
(this-win-2nd (not (and (<= (car this-win-edges)
|
||||
(car next-win-edges))
|
||||
(<= (cadr this-win-edges)
|
||||
(cadr next-win-edges)))))
|
||||
(splitter
|
||||
(if (= (car this-win-edges)
|
||||
(car (window-edges (next-window))))
|
||||
'split-window-horizontally
|
||||
'split-window-vertically)))
|
||||
(delete-other-windows)
|
||||
(let ((first-win (selected-window)))
|
||||
(funcall splitter)
|
||||
(if this-win-2nd (other-window 1))
|
||||
(set-window-buffer (selected-window) this-win-buffer)
|
||||
(set-window-buffer (next-window) next-win-buffer)
|
||||
(select-window first-win)
|
||||
(if this-win-2nd (other-window 1))))
|
||||
(error "This works only for two windows!")))
|
||||
|
||||
(provide 'gpolonkai/windows)
|
||||
|
||||
;;; windows.el ends here
|
Loading…
x
Reference in New Issue
Block a user