Emacs General

Emacs is a text editor that provides extensibility through macros, modes and configuration files. It has been in development since 1976 by Richard Stallman, who continues to maintain it. Emacs is mostly used on UNIX-like systems with X Window System as its GUI.

The emacs which-key is a command that allows users to easily find out what key they are currently pressing. It can be used in Emacs, as well as other text editors.

This Video Should Help:

I’m a Emacs fan. As someone who works with text all day, and spends a lot of time in Emacs, I think it’s worth taking the time to learn about its features. In this post, I’ll be discussing Emacs general vs hydra.

Introduction to Emacs

Emacs is a text editor that is widely used by programmers and developers. It has a wide variety of features that make it an ideal tool for editing code and other text files. One of the most unique aspects of Emacs is its “hydra” feature. This allows users to create custom keyboard shortcuts for often-used commands. This can be extremely useful for efficiency when working with large projects or files. Another great feature of Emacs is its “doom” mode, which makes it easier to navigate and work with large files. Finally, Emacs also supports remapping keys, which can be very helpful for customizing your workflow.

The Emacs Interface

Emacs is a text editor that is widely used by programmers and developers. It has a unique interface that allows users to perform various actions using keyboard shortcuts. Emacs also provides an integrated development environment (IDE) which includes features such as syntax highlighting and code completion.

One of the most notable features of Emacs is its “hydra” system. This system enables users to create custom keyboard shortcuts for frequently used commands. The hydra system is particularly useful for developers who often need to perform repetitive tasks.

Doom Emacs is a popular configuration of Emacs that includes many additional features, such as a more modern user interface and better performance. Doom Emacs is suitable for both beginners and experienced users alike.

Customizing Emacs

One of the great things about Emacs is that it is highly customizable. You can change almost anything about its behavior, including the keybindings. In this post, we’ll discuss how to customize your Emacs keybindings, and compare two popular approaches: general vs hydra.

General:

The general approach to customizing your Emacs keybindings is to use the built-in function `global-set-key’. This function allows you to remap any keybinding in Emacs, for any mode. So, if you wanted to remap the `C-x C-c` shortcut (which exits Emacs) to `C-x C-q` instead, you could do that with a single line of code:

(global-set-key (kbd “C-x C-q”) ‘save-buffers-kill-emacs)

This is a pretty simple example, but you can use `global’-set-‘key’ to bind just about anything to any key combination you want.

Hydra:

An alternative approach to customizing your Emacs keybindings is to use the Hydra package. Hydra allows you create “miniature versions of vim” which are essentially collections of related commands bound to a common prefix key. For example, suppose we wanted create a hydra for moving between windows. We could bind it to the `C-‘prefix like so:

(defhydra hydra--window () ; Define our new hydra… -* +v *+ :help “ window” t—^~ | q q..|_._| p ppp| M-| M-+ or M – )__(_____(___/%=+=%%%%%%%%^^^^^^^”” {___} “”””{___} “””{_}”^{__}”^{___} “””””{_}”””””{__}” “””””‘ ”””””'”””””””””””” ~^^()()~~^^~“““““`&&&@@@@@@@@@&&&“““““`#####$$$$$$$$$#$#$#$#$#$###$$$$$$$$$$##$##$$$$$#######$$##$$########### |||||||||||||||||||||//\\\\\\\\||||||||||||||||\///////\\\\\\\\/\\\\\\||/////////////////////////////// \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ^^^^^^^^^^^^^^^^^^^^YYYYYYYYYYYYYYYvvvvvvvvvvvvvvv^^^^^^^^^^^^^^TTTTTTTTTTTTTUUUUUUUUUWWWWWVVVVVXXXXXXXZZZZZ[[[\\\]]]^^^{{{{{{{{}}}}}}}~~~!!!!!!!!!!!!!!!!!!!!!!!!!!~~~~~~~~~~~~~~)))))))))***+++,,….—===aaaaaabbbbbccccddddeeeeeffffgggghhhhhiiiijjjjkkkkkllllmmmnnnnoooopppqqqrrrssssttttuuuuuvvvvwwxxyyzz{{|}}~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <>=>=<><><>>><<<><>>>><><>>>>>>>==<<<===>>>>>>>><<<<<=->->->-->-->—->>>>—--====—————————— ““““““`,;;;;;;;;;;::::::::::;;;;;;;;;;;;;::::::::::::;;;;;;;:::::::::::,.,.,.,.,.:,,.:,,,,,,,…

Emacs Packages

There are many different Emacs packages available, and choosing the right one can be tricky. Here is a rundown of some of the most popular options:

– Hydra: A powerful Emacs extension that allows you to create custom key bindings and macros.

– General: A versatile Emacs package that provides a wide range of features, including support for multiple buffers, window management, and file operations.

– Doom: A dark and stylish Emacs theme that is perfect for programming in Python or other languages.

– Kbd: A simple but effective Emacs package that provides keyboard shortcuts for common tasks.

– Remap: An easy-to-use Emacs package that allows you to remap keys to your liking.

Emacs Commands

There are two ways to input commands in Emacs: the default way is via the keyboard, and the other is through what’s called a “hydra”. A hydra is basically a graphical user interface (GUI) that allows you to input commands using your mouse. Personally, I prefer to use the keyboard because it’s faster and more convenient for me, but some people prefer using hydras because they find them easier to use.

The default way to input commands in Emacs is by pressing keys on your keyboard. For example, pressing “C-x C-f” will open a new file. There are hundreds of different key bindings that you can learn in order to be able to efficiently use Emacs. The best way to learn them is by reading the tutorial or by looking at the cheatsheet.

If you’re not comfortable with using the keyboard, then you can try using a hydra instead. To do this, you first need to install the Hydra package from MELPA. Once it’s installed, you can activate it by running “M-x hydra-default-keybindings” (without quotes). This will give you a menu of all the different hydras that are available. You can then choose which one you want to use and follow its instructions.

In general, I would recommend using the keyboard over hydras because it’s faster and more efficient once you get used to it. However, if you’re just starting out with Emacs then feel free to experiment with both methods until you find one that works better for you.

Emacs Macros

Emacs macros are a great way to automate repetitive tasks. With just a few keystrokes, you can record a macro and then play it back later. Macros are especially useful for editing code or text files.

There are two ways to create macros in Emacs: using the keyboard or using the menu system. To create a keyboard macro, press C-x (or F3). This will start recording your keystrokes. To stop recording, press C-x ) (or F4). You can then give your macro a name and bind it to a keystroke of your choice.

To create a macro using the menu system, select “Macros” from the “Tools” menu. This will bring up the Macro Recorder dialog box. Type in a name for your macro and press the Record button. Now perform the actions you want to record. When you’re finished, press the Stop button. You can now bind your macro to a keystroke of your choice.

Once you’ve created a macro, you can play it back by pressing the keys you assigned to it. You can also use M-x run-macro to play back a named macro without binding it to any keys. If you want to replay your last keyboard macro, simply press C-x z (or F5).

Emacs LISP

LISP is a family of computer programming languages with a long history and a distinctive, fully parenthesized syntax. Originally specified in 1958, LISP is the second-oldest high-level programming language in widespread use today. Many dialects have existed over its history, with the most prominent recent ones being Common Lisp and Scheme.

LISP was originally created as a practical mathematical notation for computer programs, influenced by the notation of Alonzo Church’s lambda calculus. It quickly became popular among programmers for its concise and flexible code. The popularity of LISP began to decline in the early 1980s due to the rise of more pragmatic languages such as C++ and Java; however, it has seen something of a resurgence in recent years due to its use in artificial intelligence (AI) applications.

There are two main types of LISP: dynamic and static. Dynamic LISPs, such as Common Lisp and Scheme, perform type checking at runtime; this allows for greater flexibility but can lead to slower performance. Static LISPs, such as Clojure and Emacs Lisp, perform type checking at compile time; this sacrifices some flexibility but results in faster execution times.

Emacs is a text editor designed for GNU/Linux operating systems that uses LISP for much of its functionality. It has been around since the mid-1970s and is widely used by programmers and system administrators due to its extensibility and customizability. One feature that sets Emacs apart from other text editors is its built-in support for macOS’s native GUI elements (such as menus and dialog boxes). This makes it a popular choice for Mac users who want an editor with more power than TextEdit but don’t want to use something as complex as vi or emacs .

Hydra:

A Hydra is an extension to Emacs that allows you to create “contextual bindings”, meaning bindings that are only active when certain conditions are met. For example, you could create a binding for the command “M-x run-tests” that would only be active when you’re editing test code files (.py files ending in “_test”). This can be extremely useful when working on large projects with many different kinds of files; it allows you to keep your bindings organized so that they only activate when you’re working on the appropriate kind of file.

The easiest way to create contextual bindings is with the “hydra” package from MELPA (the Emacs Package Archive). To install it, just open Emacs’ package manager (M-x package-list-packages), search for hydra , mark it for installation with i , then hit x to execute the changes. Once it’s installed, you can require it in your init file like so:

(require ‘hydra)

Now let’s say we wanted to create a set of contextual bindings for working with Python code files (.py). We could do something like this:

(defhydra hydra-python ()

“Python”

(“t” run-tests “run tests”) ;; M-x run python tests within project directory -or bind this directly using global keymap below without using `defhydra’ & `hydra’.. see next section.. (“r” repl “start repl”) ;; start REPL session using current project interpreter (“b” blacken “blacken buffer”)) ;; format code using black formatter (“f” fillify “fillify buffer”)) ;; format docstrings using fillup mode (“i” importmagic “importmagic buffer”)) ;; organize imports using importmagic mode (“l” lspcquerytypeatpoint “<>typeatpoint”) ;; get info about symbol under cursor via pyls server :exit t) ; exit hydra if no further input needed after completing action ;; global keymap – not specific context.. defun… not bound yet… eval or funcall.. funcall works because already defined above.. ..so now callable from any context anytime once bound… ..by default bounding keys need prefixes like C-, M-, SPC etc before them depending upon which map they belong too eiter minor or major mode maps eg:- https://withblueprintdotcomdotauhslashblogslashsettingupslashhowtoopensourceemacssettingsandconfigurationfromscratchpart3editingtextfileswithorgmodeandothermodesintroorgmodecommandscheatsheetintroductiontoemacsmodesandkeybindingsmajorkeysminormodesspccontrolcharmetakeyskbdmacrosinfopackagesusefulcommandsbasicconceptsandterminologyletmeexplainyouallaboutalllanguagespecificmodesavailableinbuiltinemacsforallmostusedprogramminglanguageslikecperlgoelisprusthaskelljavascripttypescriptrubyphpetceteraonceyouhavelearneditcompletelythenyoushallbegintounderstandwhypeoplearecallingitmagicaleditorofchoiceformanyhackersaroundglobewhoaredevoteetoopensourcecommunityifyouevergetachancetouseviortmuxorthinkscriptsthenbelievemeafterworskingwiththosedaysyourwillgetbacktoyouremacswithdoublejoybecauseofitsproductivityenhancementsthatarejustendlesscomparedtocaseofothertoolsnywaysletscomebacktopythonnowwhereweleftoffearlierthatisdefiningourcustomkeysbindingsusingfunctionnamedefhydradownbelowweremakingthisbindingavailablegloballynotonlyspecificcontextlikepreviousoneinsteadweremakingitworkeverytimeusetypeC-,btodoanythingrelatedtopythonaslongaspackagerequirementisloadedcorrectlywhichisexpandedonesectionabovenowseeexamplebelowbutbeforeproceedinganyfurtherpleasereadnextsectionaboutdiscoverabilityfirstbecausewithoutknowingittheresnochanceyouwillbeabletoactivateanyofthesecommandssimplyputitisassumedherethatyouhavepriorknowledgeaboutactivationmechanismoffeaturesdescribedindocumentationofeachfeaturepackagepresentedinmelpaarchivewhetherthosetheiraliasesdirectoriesrepositorywebsitesetceteraetceterabutstillifneededrefertosectionbelowregardingaccesstomelpaquickpackagemanagersearchinterfaceinteractivelywithinbuffergoingthroughlistswithoutleavingcurrentbufferfocuspleaselearninghowtoreadmanpageshelpdocumentationinfoinsidebuiltinemacsclientinfowillhelpyoutounderstandwhatkindsoffunctionalitiesfeaturescapabilitiesadvantagesdisadvantagesetceteraareavailablerightatthefingertipsinyourfavoriteeditoritselfpluswhatextensionspluginspackagesadditionscustomizationssettingsconfigurationsmodificationsenhancementsimprovementsfixespatchesbugreportsissuespullrequestsnewfeaturescontributionssubmissionspressreleasesannouncementsblogsarticlesdocumentationsscreencastsvideosgifsfactsquotesmemesjokesfunniestuffrandomthoughtsguidesHOWTOsFAQsacrosswidevarietyofthemespacksbundlescollectionsfamiliesdistrosflavoursversionsbranchesderivativesforksofallkindsyoumayfindduringdailyusageasyougainmoreexperiencewhileworkingwithdifferentsetupsenvironmentsoperatingsystemsyouwillreachapointwherenothingcanstopyoufromreachingyourultimategoalndthatisafter masteringartcraftscienceofworkingwithbestpracticesapproachmethodologyphilosophydoctrineguidelineprinciplefollowedbycommunityconsensusdecisionconventiontradecraftskilltooltechniqueplatformtechnologystackstandardframeworkusedtodaygenerallyacceptednormprocessprotocolconventionsubsystemcomponentlibraryAPIcommandlineutilityapplicationsoftwarepackagecodeprogramminglanguageresideoftheworldwideinternethackerdominationdreamvisionmissionobjectivetargetmilestonepurposeresultoutcomebenefitfinaldestinationendgamefilefolderdirectorypathnametreebranchhistorycommitlogchangesdiffpatchblameannotationversioncontrolsystemVCScommonlyknownasthedevilscodeRMSRichardStallmanfounderleaderpioneerencouragerpromoterdevelopercontributorinnovatorcreatorgodfatherguardianangelrevolutionaryfree softwaremovementopen source movementcopyleftGNUprojectGPLGNUEMACSOSIOpen Source InitiativeMITlicenseBSDlicenses Apachelicensedesignpatternsingletonmediatorfacadebuilderstrategyobserverdecoratorproxychainiteratorcompositeflyweightvisitorstatemomentochainresponsibilitycoroutinepublishsubscribeconsumerproduceractormessagebrokerworkerthreadpooltaskfuturepromisesequencestate machineflowautomatafinite state automatonregular expressiongraphdatabasesqlnosqlobject relational mappingORMdata modelingentity relationshipdiagramERDmodel view controllerMVCmicroservicesdistributedarchitectureevent busmessage queuejob schedulerload balancer

Emacs Tips and Tricks

1. If you’re using Emacs, there’s a good chance you’re using it for programming. As such, you might find yourself frequently needing to open files in different directories. A simple way to do this is to use the “find-file” command (usually bound to C-x C-f). However, this command prompts you for the directory every time. A faster way is to use the “find-file-in-project” command (usually bound to C-x f), which will start searching from the root directory of your project.

2. Another common issue when programming is that you might need to quickly switch between files that are related (e.g., between a .h and .c file). The “switch-window” command (usually bound to C-x o) lets you quickly switch between windows without having to type out the filename each time.

3. One of the great things about Emacs is that it’s highly customizable. If there’s a key binding that you don’t like, or if there’s something that you wish Emacs could do but doesn’t, chances are there’s a way to change it. For example, let’s say you want to remap the key binding for opening a new line and indenting from C-j to M-j. You can add the following line of code to your ~/.emacs file:

(global-set

Emacs is a text editor that has been around for decades and is still going strong. The “emacs evil” is a term used to describe when the user has done something wrong, but doesn’t know what it was.

External References-

https://stackoverflow.com/questions/72242261/using-the-general-with-use-package-sometimes-doesnt-work

https://www.reddit.com/r/emacs/comments/kjk0lx/moving_to_general_from_usepackage_keybindings/

Scroll to Top