Skip to content

Instantly share code, notes, and snippets.

View jamescherti's full-sized avatar

James Cherti jamescherti

View GitHub Profile
@jamescherti
jamescherti / region-markdown-to-org.el
Created March 3, 2025 17:15
Emacs: Convert selected Markdown text to Org format using Pandoc
;;; region-markdown-to-org.el --- Emacs: Convert selected Markdown text to Org format using Pandoc -*- lexical-binding: t; -*-
;; Gits URL:
;; License: MIT
;; Author: James Cherti
(defun my-markdown-to-org (beg end)
"Convert selected Markdown text to Org format using Pandoc
BEG and END are the beginning and end of the selection."
(interactive "r")
(if (use-region-p)
;;; auto-scroll-message-buffer.el --- Auto scroll the *Messages* buffer -*- lexical-binding: t; -*-
;; Gits URL:
;; License: MIT
;; Author: James Cherti
(defun my-auto-scroll-message-advice (&rest _)
"Go to point-max after a message in *Messages* buffer."
(walk-windows
(lambda (window)
(let ((window-buffer (window-buffer window)))
@jamescherti
jamescherti / add-hyphen-bash-imenu.el
Last active April 7, 2025 13:03
Emacs Bash scripts imenu: Support hyphens in function names
;;; add-hyphen-bash-imenu.el --- Bash scripts imenu: Support hyphens in function names -*- lexical-binding: t; -*-
;; Gits URL: https://gist.github.com/jamescherti/3dcfe5b67b69a331b09c3db66e82d5fc
;; License: MIT
;; Author: James Cherti
;;
;; This patch has been integrated into Emacs:
;; https://lists.gnu.org/archive/html/emacs-devel/2024-11/msg00684.html
(with-eval-after-load "sh-script"
;; By default, imenu does not include functions with hyphens in their names by
@jamescherti
jamescherti / clone-indirect-buffer-current-window.el
Last active November 13, 2024 03:51
Emacs: Create an indirect buffer and switch to it
;;; clone-indirect-buffer-current-window.el --- Create an indirect buffer and switch to it.. -*- lexical-binding: t; -*-
;; Gits URL: https://gist.github.com/jamescherti/686d8cb3d636614cefe76c6fc7b76e55
;; License: MIT
;; Author: James Cherti
(defun my-clone-indirect-buffer-current-window (&optional newname norecord)
"Create an indirect buffer and switch to it.
Creates a new indirect buffer with the same content as the current buffer,
preserving point position, window start, and horizontal scroll position. The
original buffer remains unchanged.
@jamescherti
jamescherti / disable-truncation-arrow.el
Last active November 5, 2024 14:56
Emacs: Disable the truncation arrow.
;;; disable-truncation-arrow.el --- Disable the truncation arrow. -*- lexical-binding: t; -*-
;; Gits URL: https://gist.github.com/jamescherti/45c7f70d316c5d707910cbd1fdb676cb
;; License: MIT
;; Author: James Cherti
(defun my-disable-fringe-truncation-arrow ()
"Disable the truncation arrow."
(unless (boundp 'fringe-indicator-alist)
(error "The fringe-indicator-alist was not declared"))
(setq fringe-indicator-alist
@jamescherti
jamescherti / delete-before-cursor-except-asterisks.el
Last active October 25, 2024 00:17
Emacs Evil Org-mode: Delete everything before the cursor except the first '*' and space.
;;; delete-before-cursor-except-asterisks.el --- Emacs Evil Org-mode: Delete everything before the cursor except the first '*' and space. -*- lexical-binding: t; -*-
;; Gits URL: https://gist.github.com/jamescherti/15168bb060d79a5c57215e62dd9bfa55
;; License: MIT
;; Author: James Cherti
(with-eval-after-load "org"
(with-eval-after-load "evil"
(defun my-evil-delete-to-heading-star ()
"Delete everything before the cursor except the first '*' and space.
@jamescherti
jamescherti / save-marker-and-window.el
Created October 23, 2024 16:59
Emacs: Save point as a marker, window start/hscroll, restoring them after BODY.
;;; save-marker-and-window.el --- Emacs: Save point as a marker, window start/hscroll, restoring them after BODY. -*- lexical-binding: t; -*-
;; Gits URL: https://gist.github.com/jamescherti/8921b341b628599ca8c7ff7f173a435a
;; Usage: (my-save-marker-and-window (progn (your-code argument)))
;; License: MIT
;; Author: James Cherti
(defmacro my-save-marker-and-window (&rest body)
"Save point as a marker, window start/hscroll, restoring them after BODY."
`(let ((point-marker (copy-marker (point)))
(window-start-marker (copy-marker (window-start)))
@jamescherti
jamescherti / shell-command-first-line-to-string.el
Last active October 23, 2024 16:57
Emacs Lisp: Return the first line of output from executing COMMAND.
;;; shell-command-first-line-to-string.el --- Return the first line of output from executing COMMAND. -*- lexical-binding: t; -*-
;; Return the first line of output from executing COMMAND.
;; If the command fails or produces no output, return nil.
;;
;; This function is superior to `shell-command-to-string` because it allows
;; for the detection of command execution failures by examining the exit status.
;; While `shell-command-to-string` only returns the output as a string,
;; it does not provide information about whether the command succeeded or failed.
;; By using `call-process-shell-command`, this function can capture both
;; the output and the exit status, enabling better error handling
@jamescherti
jamescherti / describe-elisp-symbol-at-point.el
Last active September 17, 2024 12:32
;;; my-describe-symbol-at-point.el --- Describe variable or function at point -*- lexical-binding: t; -*-
;;; describe-symbol-at-point.el --- Describe variable or function at point -*- lexical-binding: t; -*-
;; Description: Clear the contents of the *Messages* buffer if it is the current buffer.
;; Gits URL: https://gist.github.com/jamescherti/abb288cb98f5f9f08431cc29225273fe
;; License: MIT
;; Author: James Cherti
(defun my-describe-elisp-symbol-at-point ()
"Describe the symbol at point as either a variable or a function.
This function determines whether the symbol at point is a variable or a
@jamescherti
jamescherti / clear-messages-buffer.el
Last active August 23, 2024 22:08
Emacs: Clear the contents of the *Messages* buffer if it is the current buffer
;; Description: Clear the contents of the *Messages* buffer if it is the current buffer.
;; Gits URL: https://gist.github.com/jamescherti/52e8fe8700ab394163bb99f2b8d456fd
;; License: MIT
;; Author: James Cherti
(defun my-clear-messages-buffer ()
"Clear the contents of the *Messages* buffer if it is the current buffer."
(when (string= (buffer-name) "*Messages*")
(let ((was-read-only buffer-read-only))
(when was-read-only