Skip to content

My personal Emacs configuration files for Windows 10

Notifications You must be signed in to change notification settings

harryrberg/emacs-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Emacs Configuration

This guide provides a comprehensive configuration file for setting up a personalized and efficient Emacs experience tailored for Windows 10 users. The configuration file covers performance optimization, package management, appearance customization, environment settings configuration, as well as the setup of Org mode and ChatGPT API integration.

Installing Emacs on Windows 10 using Chocolatey

Open a Command Prompt or PowerShell window with administrative privileges. Enter the following command to install Chocolatey:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Enter the following command to install the latest version of Emacs:

choco install emacs

Verify that the installation was successful by entering the following command:

emacs --version

Setting User Environment Variables

Right-click on the Computer icon on the desktop or in the Start menu, and choose Properties. Click on Advanced system settings in the left sidebar. In the System Properties window, go to the Advanced tab and click on the Environment Variables button. In the User variables section, click on the New button. Set the Variable name as HOME and the Variable value as %USERPROFILE%. Click OK to save the changes. Click on the New button again in the User variables section. Set the Variable name as EMACS_SERVER_FILE and the Variable value as %USERPROFILE%.emacs.d\server\server. Click OK to save the changes. Click OK to close the Environment Variables window and then click OK again to close the System Properties window.

Configuring Emacs

Open the init.org file in Emacs. Customize the init.org file according to your preferences. Use the **org-babel-tangle** command to generate the init.el file. This command will extract the Emacs Lisp code blocks from the Org file and put them into the init.el file in the same directory. Restart Emacs to apply the changes.

Preamble

This section configures the automatic tangling of the init.org file upon saving, ensuring that the init.el file is always up-to-date with the latest changes.

Tangle init.org upon saving

When the init.org file is saved, this function will automatically tangle it, creating or updating the init.el file accordingly.

(defun tangle-init-file ()
  (when (equal (buffer-file-name) (expand-file-name "~/.emacs.d/init.org"))
    (org-babel-tangle)))
(add-hook 'after-save-hook 'tangle-init-file)

Performance

This section optimizes Emacs startup and runtime performance by adjusting garbage collection settings.

Optimize startup performance

Set the garbage collection threshold to its highest value during startup to speed up the process.

(setq gc-cons-threshold most-positive-fixnum)

Optimize runtime performance

Restore the garbage collection threshold to a more reasonable value after Emacs has started to optimize runtime performance.

(add-hook 'emacs-startup-hook (lambda () (setq gc-cons-threshold 16777216)))

Package Management

This section sets up package.el and use-package for managing Emacs packages. It configures package repositories, initializes the package system, and ensures that use-package is installed.

Setup package.el and use-package

Configure package.el by setting the package repositories, initializing the package system, and ensuring that Org Mode and use-package are installed.

(require 'package)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("gnu" . "https://elpa.gnu.org/packages/")))
(package-initialize)
(unless package-archive-contents
  (package-refresh-contents))

;; Install Org Mode from GNU ELPA
(unless (package-installed-p 'org)
  (package-install 'org))

;; Install use-package if not already installed
(unless (package-installed-p 'use-package)
  (package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)

Appearance

This section configures the appearance of Emacs, including disabling toolbars, scrollbars, and menubars, as well as customizing the startup screen, font, and theme.

Disable toolbars, scrollbars, and menubars

Disable the tool bar (icons), scroll bar, and menu bar.

(tool-bar-mode -1)
(scroll-bar-mode -1)
(menu-bar-mode -1)

Inhibit startup screen

Do not show the startup screen.

(setq inhibit-startup-screen t)

Set initial scratch buffer message to nil

Remove the default message in the scratch buffer.

(setq initial-scratch-message nil)

Set font

Set the default font to “JetBrains Mono” with size 15.

(defun my/set-frame-font ()
  (set-frame-font "JetBrains Mono-15" nil t))
(add-hook 'after-make-frame-functions
          (lambda (frame)
            (select-frame frame)
            (my/set-frame-font)))
(my/set-frame-font)

Theme

Configure and load the ‘modus-operandi’ theme, with slanted and bold constructs enabled.

(use-package modus-themes
  :ensure t
  :init
  (setq modus-themes-slanted-constructs t
        modus-themes-bold-constructs t)
  :config
  (load-theme 'modus-operandi :no-confirm)
  ;; OR (modus-vivendi)
  )

Environment

This section configures the environment settings for Emacs, such as the initial working directory and fullscreen behavior.

Set initial working directory

Change the initial working directory to the user’s home directory.

(cd "~")

Fullscreen

Function to toggle fullscreen

Define a function that toggles the fullscreen state of the Emacs window.

(defun toggle-fullscreen ()
  (interactive)
  (if (eq (frame-parameter nil 'fullscreen) 'fullboth)
      (set-frame-parameter nil 'fullscreen nil)
    (set-frame-parameter nil 'fullscreen 'fullboth)))

Bind F11 key to toggle fullscreen

Set the F11 key to call the `toggle-fullscreen` function.

(global-set-key [f11] 'toggle-fullscreen)

Set initial and future frames to fullscreen

Configure Emacs to start in fullscreen mode and apply fullscreen settings to future frames.

(add-to-list 'default-frame-alist '(fullscreen . fullboth))

Set fullscreen for new frames created by the daemon

Ensure that new frames created by the Emacs daemon start in fullscreen mode.

(defun set-fullscreen-for-new-frame (frame)
  (set-frame-parameter frame 'fullscreen 'fullboth))
(add-hook 'after-make-frame-functions #'set-fullscreen-for-new-frame)

Org Mode

This section configures Org Mode settings and appearance, such as hiding leading stars, setting agenda files, and defining TODO keywords.

Load Org Mode and set up basic settings

Load Org Mode and configure basic settings, such as hiding leading stars, setting agenda files, and defining TODO keywords.

(use-package org
  :config
  (setq org-hide-leading-stars t
        org-agenda-files '("~/org")
        org-todo-keywords '((sequence "TODO" "IN-PROGRESS" "WAITING" "DONE"))))

Load Org Tempo for structure templates

;; Require org-tempo and add custom Org Tempo template

(require 'org-tempo)

(defun org-tempo-src-emacs-lisp-tangle-yes ()
  "Insert an emacs-lisp source block with :tangle yes option."
  (interactive)
  (let ((content (org-tempo--expand-structure-template '("se" . "src emacs-lisp :tangle yes"))))
    (insert content)
    (search-backward "#+END_SRC")))
(with-eval-after-load 'org-tempo
  (add-to-list 'org-structure-template-alist '("se" . "src emacs-lisp :tangle yes")))

Org-ai Configuration

This section of the Emacs configuration sets up the org-ai package to enable GPT-4 integration with Emacs’ Org mode. It loads the API token from an external file (secret.el) and configures org-ai settings. Additionally, it installs AI snippets for Yasnippet if you use it.

Usage

Create a file named “secret.el” in your Emacs configuration directory (~/.emacs.d/). Add the following line to “secret.el”, replacing “your_api_key_here” with your actual OpenAI API key:

(setq my-openai-api-token "your_api_key_here")

Add the provided org-ai configuration code to your Emacs configuration file.

Features

Enables GPT-4 integration with Org mode for AI-assisted text generation. Automatically installs AI snippets for Yasnippet (optional).

(use-package org-ai
  :ensure
  :commands (org-ai-mode)
  :init
  ;; Load secret.el
  (load-file "~/.emacs.d/secret.el")
  :custom
  (org-ai-openai-api-token my-openai-api-token)
  :config
  ;; Set the default chat model to GPT-4 (replace "gpt-4" with the actual GPT-4 model name)
  (setq org-ai-default-chat-model "gpt-4")
  ;; if you are using yasnippet and want `ai` snippets
  (org-ai-install-yasnippets))

About

My personal Emacs configuration files for Windows 10

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published