Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3696506
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:44:50+00:00 2026-05-19T04:44:50+00:00

I am working in Haskell and frequently come across code similar to the following:

  • 0

I am working in Haskell and frequently come across code similar to the following:

func i j | i == j = i
         | otherwise = j

I want to align on the ‘=’ character using align-regexp but don’t have the elisp knowhow. I have tried just doing ” = ” without the quotes, but this inserts an unwanted space character before each ‘=’. I have found a proposed solution here but I can’t seem to get that to do anything at all.

Please help me write a function or hard-coded macro that will allow me to set a keybinding for this.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:44:50+00:00Added an answer on May 19, 2026 at 4:44 am

    C-u M-x align-regexp RET \(\s-*\) = RET 1 RET 0 RET n

    (n.b. there’s a space after the ‘=’, but it’s not very obvious.)

    Which is to say…

    Use a prefix argument to tell align-regexp to ask you for more parameters than it does by default.

    See C-h f align-regexp and C-h v align-rules-list for details, but in short:

    \(\s-*\) is the default ‘group’ for deletion/expansion. We append our pattern to the end of that: ‘ = ‘. (Note that \s- is Emacs regexp syntax for whitespace.)

    1 simply refers to parenthesised group 1 (as above). This is the default.

    0 for the spacing to use between the two parts of the line. By default this is 1, and is why you were ending up with an additional space.

    n to not align any subsequent pattern matches after the first in each line.

    edit: Actually, the Q&A you linked to is near identical, and works fine for me on Emacs 23.2.1, so this is a duplicate, but to continue and answer the key-binding aspect:

    You can bind that (or any) sequence via keyboard macros. Here’s the end result, which you can probably just add to your init file, although I recommend you go through the process yourself. Use whatever you like in place of C-c a for the key. C-c (letter) and F5-F9 are reserved for end-users to bind as they please, so one of those will be safe from being clobbered by a mode’s keymap.

    (global-set-key (kbd "C-c a") (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([21 134217848 97 108 105 103 110 45 114 101 103 101 120 112 return 32 61 32 return return backspace 48 return 110] 0 "%d")) arg)))
    

    I did that by:

    1. selecting the text.
    2. F3 to start recording.
    3. performing the align-regexp as above (being careful to type everything verbatim, and not use minibuffer history or yanking).1
    4. F4 to stop recording.
    5. C-x C-k n align-single-equals RET to give the macro a name
    6. M-x insert-kbd-macro RET align-single-equals RET to get the lisp.
    7. Wrapping the (lambda) expression with (global-set-key) to bind it. (Although you could also use the (fset 'align-single-equals ...) code as provided, and then bind the key to that symbol.

    1 If you make a mistake when recording a complicated macro, don’t fret — Emacs provides a really good macro editor which you can use to fix any mistakes after you finish recording (just type C-x C-k e), so you don’t need to be perfect.

    edit 2: May as well add an example of a function, as per comments.

    (defun my-align-single-equals ()
      "Align on a single equals sign (with a space either side)."
      (interactive)
      (align-regexp
       (region-beginning) (region-end)
       "\\(\\s-*\\) = " 1 0 nil))
    
    (global-set-key (kbd "C-c a") 'my-align-single-equals)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on the problem for writing Haskell code similar to a C++
I'm working on a haskell web app using yesod that I eventually want to
While working through Real World Haskell, I tried to complete the palindrome exercise using
I'm working through Learn You A Haskell in order to come up to speed
I'm working on parsing with haskell, I want to parse a timestamp value expressed
I'm a complete noob to Haskell I cant get my code working at all
I'm working on designing a larger-ish web application using Haskell. This is purely for
I'm stuck trying to get multiple textures working in OpenGL using Haskell. I've been
I want to tackle some image-processing problems in Haskell. I'm working with both bitonal
I'm working on some Haskell project using FFmpeg . I need to batch create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.