Enhancing Code Blocks in Org & Markdown

Polymode provides "multimode" functionality. It allows you to work
with multiple major modes within a single file, enabling appropriate
editing features and syntax highlighting for different code blocks or
sections. This is particularly useful when dealing with files
containing mixed content, such as Markdown files with embedded code
blocks.

An elisp example

;; add code markers like ```elisp around a block of code in Markdown
(defun my-insert-code-block (lang)
  "Insert a fenced code block with the specified language in a Markdown file."
  (interactive "sLanguage: ")
  (insert (format "```%s\n" lang))
  (save-excursion
  (insert "\n```\n")))

(global-set-key (kbd "C-c M-b") 'my-insert-code-block)

A bash example

#!/bin/bash

directory="."

for file in "$directory"/*; do
  new_file=$(echo "$file" | sed 's/[_ ]\+/-/g')
  if [ "$file" != "$new_file" ]; then
  mv "$file" "$new_file"
  fi
done

My Polymode Configuration

  (use-package polymode
  :ensure t
  :config
  (use-package poly-markdown
  :ensure t
  :mode ("\\.md\\'" . poly-markdown-mode)))

(use-package poly-org
  :ensure t
  :mode ("\\.org\\'" . poly-org-mode))

Return to Home