OK, first the alignments and then the explanation of how it works.
To align the first one, select the lines, do C-u M-x align-regexp and choose: \(\s-*\):, 1, 1, and y.
For the second, use ,\(\), 1, 1, and y.
How it works:
The regexp is tried on every line in the region. On each, if the lines are not aligned already, it will match on a different column. ...
According to the manual node on Filling, several of the fill functions take an optional JUSTIFY argument that you can use. So, for example, to fill a paragraph with right justification, you can use (fill-paragraph 'right).
You can also use (justify-current-line 'right) for a single line.
If you plan to use these options a lot, you could wrap them in ...
When the cursor is somewhere in the entry, run the command bibtex-fill-entry (bound to C-c C-q), which will
align the fields. You may also want to set variable bibtex-align-at-equal-sign to a non nil value to change the details of alignment.
First, you need to be sure that the buffer is in Text mode:
Once in text mode, C-- M-x align (which invokes the text-dollar-figure alignment rule) will align the first decimal vertically. But it fails to align the second decimal column. Plus it fails to align numbers that don't have an explicit decimal point (such as wolfram-mathematica's ...
The result that you want is already an AUCTeX feature since October 2013. This is not yet present in the current release (11.87).
All you have to do is mark the region and hit TAB.
See LaTeX-hanging-ampersand-position for how the indentation is implemented.
This depends on the fonts you are using. And I don't think Elisp has pixel level alignment capability.
Org calculate width of string with string-width instead of length. string-width returns 1 for ASCII and Half width CJK chars or 2 for Full width chars. Evaluate the following code will show you that:
I wouldn't use align-regexp but the wonderful orgtbl-mode for this: if you enable this minor mode, it will automatically recognize the table, and change its size as needed (use tab to move around in the table).
This took me quite a bit more time than I originally estimated, and the code is a bit too long to post it all here, so I posted it to Patebin: http://pastebin.com/Cw82x11i
It is not entirely complete though and it can use some more work, so if anyone will have suggestions or contributions, I might re-arrange this as a Git repository somewhere / repost this ...
Judging from your screenshots, you are using a monospaced font in centos, but a proportional/variable-width font in Windows.
I haven't looked at the source code, but I suspect that the alignment functions are based on the number of characters in the line and not the width of each, individual character. As such, they will line up visually with no problems ...
If you'd like to mark a region for auto-alignment, then it's probably not too hard to do with something like:
(defvar my--auto-align-overlays nil)
(defun my-auto-align (beg end regexp)
(interactive "r\nsRegexp: ")
(let ((ol (make-overlay beg end)))
(overlay-put ol 'evaporate t)...
Assuming that you don't have any blank lines between the \begin and \end of your equations, you can call this function while your cursor is anywhere within the \begin-\end region.
(defun my/align-latex-eq ()
"Align the & chars and then align the +/= chars."
;; align-regexp syntax: align-...
If you are on a UNIX-type system (Linux, BSD, OSX) you can use the paste command.
Select the region in Emacs, then call shell-command-on-region with an argument (to replace the selection with the result).
For example, to format into 3 columns, type:
paste - - -
It turns out that the behavior of a given regexp is dependent upon the syntax table of the buffer in which it is being run. So in your case, the \s- matches any character that is part of the whitespace syntax class in that buffer. If the newline characters is part of that syntax class, then you have the possibility of getting matches that span multiple ...
After digging through source, I failed at finding any such hook. So as a final resort you can advice the function help-button-action to recenter after jump.
(defun my-recenter-on-find-function (orig &rest args)
(let ((result (apply orig args)))
(advice-add 'help-button-action :around #'my-recenter-on-...
I should have googled a bit more before asking.
I can align the code by selecting it and applying align-regexp with an argument of =.
Feel free to give a potentially better and/or more detailed answer, I'll accept it.
Puppet Mode provides puppet-align-block. You could arrange for this function to be called automatically, e.g. by adding it to post-command-hook locally (untested):
(defun puppet-auto-align ()
Thanks, @Dan and @Matthew Piziak for your help!
Indeed, Aquamacs seems to have its own font definitions:
Switching to a mono-spaced (fixed pitch) font throughout
Aquamacs uses a mono-spaced font (Monaco) as a default, but uses the system’s
variable-width font (Lucida Grande) for all text modes, including
those derived from ‘text-mode’.
To use ...
My approach would be a bit different:
Figure out the height of the content to be centered
Display a newly created buffer in a window
Figure out the window's height
Insert a newline with the display property to make it appear tall enough with the height
An actual implementation is demonstrated in the magic-buffer package, it differs from the ...
There is a recenter command that should do what you want: it will center the line containing point in the current window.
Depending on how you want things to recenter as the paragraph grows, you may want to count the lines in the paragraph and move point to the middle line before calling recenter each time. You also need enough empty lines before the ...
You can :
go to the right relevant line (with isearch C-s 'pattern') and do C-l (recenter-top-bottom) 2 times.
go to the left relevant line (same iseach C-s C-s) and do C-l 2 times.
the two buffers will be align.
The cursor will be at top position if scroll-margin == 0 (default value).
if not, add (setq scroll-margin 0) to your .emacs
You can send the code and any instructions to Emacs for its inclusion, using M-x report-emacs-bug. Sending a patch is preferred.
Or you can make the code available from a GIT repository or at Emacs Wiki. At Emacs Wiki you can just copy+paste the code into your web browser - no need to set anything up locally etc.
The following is the solution from Jordon Biondo at "Writing PHP with SQL queries in emacs" supplemented by alignment of the first spaces and equal signs.
You can further adapt the alignment rules in align to your liking (see the description of the variable align-rules-list).
The packages expand-region and sql-indent from MELPA are required. (That is ...
With indent-tabs-mode set to nil1, the following will do most of that:
C-uM-x align-regexp RET ,\(\s-*\) RET RET y
Dealing with the initial parameter is decidedly trickier. If you can guarantee the presence of a space after each comma, then you could use the following regexp along with 0 for the "Amount of spacing" question:
I had a similar issue, when using the smartparens package in bibtex-mode, where shameful amounts of spaces where inserted. For some reason unknown, bibtex-mode sets the fill-prefix variable to a string containing 18 spaces. (setq fill-prefix nil) in the bibtex-mode-hook fixed the issue in my case.
align-regexp is called non-interactively like that:
(align-regexp BEG END REGEXP &optional GROUP SPACING REPEAT)
The argument REGEXP of align-regexp is a regexp that should contain at least one group.
For alignment characters are deleted from the back of the substring matching the first group or whitespace is inserted at the back of that substring.
Based on the comments, it seems clear that there was a bug in sh-mode in Emacs 23.1 which was fixed in some subsequent version (certainly by 24.5). So that explains "what is wrong".
If you cannot upgrade Emacs, you could try just using the sh-script.el from a newer version -- it's possible that it will work.
n.b. Any newer version which depends on lexical ...
Without really knowing anything about this, can't you just define your own my-align or my-align-regexp command that invokes the standard command after binding indent-tabs-mode to nil?
If, in that context, you want spaces only, then just turn the mode off in that context (and turn it back on again when the command is done).
E.g., something like this (...
align is aligning those // comments to the value of comment-column in that buffer, which will be column 32 by default. Your for statement extends beyond that column, so it is out of alignment.
See C-h f comment-set-column. Use that, and then M-x align again.
See, it adds multiple spaces around x. Why?
Because it has aligned the = characters in the two ...