Showing posts with label Emacs. Show all posts
Showing posts with label Emacs. Show all posts

2019-03-23

Homebrew blew up from libffi, ruby, or? Here's how to fix it.

I wanted to upgrade Homebrew itself and what it installed on my Mac.  It's probably been over a year, so lots of outdated stuff.  I ran:

brew update
brew upgrade

Everything looked good, and it gave me some instructions to add to my PATH the Homebrew installed ruby and ruby gems along the lines of adding the following to my .bash_profile:

PATH="/usr/local/opt/ruby/bin:$PATH"
PATH="/usr/local/lib/ruby/gems/2.6.0/bin:$PATH"

So I did that, and tried out ruby, irb, and emacs. It starts spitting a bunch of different errors, and I probably confounded the causes and errors as I was trouble shooting, but it gave me errors about:

dyld: Library not loaded: /usr/local/opt/libffi/lib/libffi.6.dylib

Especially when I ran emacs, I got:

dyld: Library not loaded: /usr/local/opt/libffi/lib/libffi.6.dylib
Referenced from: /usr/local/opt/p11-kit/lib/libp11-kit.0.dylib
Reason: image not found

And when I ran irb, I got:

Traceback (most recent call last):
2: from /usr/local/opt/ruby/bin/irb:23:in `<main>'
1: from /usr/local/Cellar/ruby/2.6.2/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
/usr/local/Cellar/ruby/2.6.2/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': can't find gem irb (>= 0.a) with executable irb (Gem::GemNotFoundException)

Hmm?  I tried a bunch of stuff and it probably made it more confusing, especially as I started running brew and got errors like:

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- active_support/core_ext/object/blank (LoadError)

Or when I ran brew help and got:
 
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- mechanize/version (LoadError)

Well now I just wanted to "start over".  You could do that by deleting all of Homebrew and what it installed, to start fresh, but what a pain!  I'd have to know what packages to re-install with a new Homebrew installation and go through installing those one by one.

Instead, the easier thing to try first is this:

1. Remove from your PATH the brew installed ruby and rubygem

On Macs, it's probably "safest" when troubleshooting Homebrew to use the Mac OS X's original Apple installed ruby.  Yes, it's an old version of ruby, but when I changed my PATH to use the Homebrew installed ruby, I probably made troubleshooting much more difficult.  It's tough enough to troubleshoot Homebrew, but if brew (a ruby program) runs on the brew installed ruby, brew just might be running on a ruby that brew screwed up...

2. try brew update-reset

This fetches and resets Homebrew and all tap repositories to the latest from their git repositories.  In other words, restart them fresh.

3. brew reinstall libffi

emacs, ruby, python, and a bunch of other stuff needs it.  Even if you've got it installed.  Reinstall it to make sure it's installed right.  It fixed emacs for me for sure.  Probably ruby too.

4. update and upgrade brew again

brew update
brew upgrade

And that finally fixed it.  I added the ruby and gem paths back into PATH in my .bash_profile, and installed irb as a ruby gem (Mac OS X has old versions of both ruby and irb pre-installed, but getting the latest means installing ruby via brew and irb as a ruby gem).

2011-01-18

Emacs Spell Check in Mac OS X

If you use emacs on a Linux or non-Mac Unix machine, it probably already has iSpell installed and configured so you could spell check in emacs (eg, use M-$).

In Mac OS X, you'll do well to use ASpell instead via CocoaASpell.

In Windows...I don't know.  There is an ASpell ported to Win32, but it is horribly out of date.

If you know a good emacs spell check solution for Windows, let me know in the comments below.  Thanks.

2011-01-01

Emacs Fonts

I use emacs on Windows, Mac, and Ubuntu Linux, and I've been trying to keep my .emacs file in sync on all three platforms.  One thing that bothered me was the font.  It looked good on Ubuntu without my setting it, but when I go to Windows or Mac (in X11), the default font was just no good.

So to fix it, I went to Revisiting Programming Fonts to select the fonts I wanted: Consolas on Windows, and Inconsolata on Mac.  I installed those as you usually would in each respective operating system (emacs will use the system available fonts).

And then I put this in my .emacs file:

(if (string= (symbol-name system-type) "windows-nt")
    (set-default-font "-outline-Consolas-normal-normal-normal-mono-18-*-*-*-c-*-iso8859-1")
  (modify-frame-parameters nil '((wait-for-wm . nil))))

(if (string= (symbol-name system-type) "darwin")
    (set-default-font "-outline-Inconsolata-normal-normal-normal-mono-18-*-*-*-c-*-iso8859-1")
  (modify-frame-parameters nil '((wait-for-wm . nil))))

Now, I get Consolas font on Windows, and Inconsolata on Mac, and whatever was my default on Ubuntu that I didn't have to set manually!

If you don't know what fonts are available, it turns out you could find out in emacs by doing M-x set-face-font, then choose default, then hit the tab key twice to see the completion listing.  Scroll through the listing until you see the font name you want.  After noting down the name, just hit C-g several times to exit out of set-face-font so you could make the selection permanent by making the above adjustment in your .emacs file.

2010-11-19

emacs search and replace over multiple files

The built-in emacs search and replace facility is pretty great, but doing the same thing over multiple files is a bit of a pain.

There is a great package that makes it easy though: FindrPackage.

Install it using elpa package manager, but I had to do some manual adjustment of my .emacs file afterwards (not sure why the installer didn't automatically do this). The adjustments are documented under the heading "Installation" here.

One thing to note though. Findr's search and replace is interactive, so that's great. But the recursive find isn't obviously interactive, and after the first search result, you may be confused as to how to go to the next result. The key is to use the M-x tags-loop-continue command.

You may want to remap a key binding to make tags-loop-continue easier, by inserting into your .emacs file this line:

(define-key global-map [(meta ,)] 'tags-loop-continue)

Then a simple M-, after using Findr's search function will let you incrementally search for the next result in the files you indicated to be searched through.

2010-11-12

Obscure and often used emacs key bindings

Nowadays I juggle programming Clojure in emacs on Ubuntu, and C++ in Visual Studio on Windows.  Despite using what emacs key bindings I can in Visual Studio, I still have to keep track of two very different text editors.

So I'm going to start collecting some emacs key bindings I often use here that are, well, obscure:

Formatting text:

C-M-\ for applying auto-indenting on a marked region
M-q for applying auto-hard-line-breaking on a marked region

Using registers:

C-x r s n for copying text in marked region into register n, for n between 0 - 9 (and apparently other single ascii char, but I'm not sure).
C-x r r n for copying text in marked rectangular region into register n.
C-x r i n for inserting text from register n to current point (be it rectangular or otherwise).

C-x r SPC n for copying the current point/location in the file into register n.
C-x r j n for jumping to the point/location in the file saved into register n.

(See also Registers and Bookmarks.)

In paredit mode:

C-u del or C-u C-d to force the deletion of a character (without paren matching getting in the way)
C-q x for arbitrary character x will force insert the character x (without paren matching getting in the way)

That's all for now.

2010-09-23

Emacs on Windows 7, and setting up ColorTheme

Wanting Emacs on Windows 7?  The install is easy.  There is nice but old instructions over at Installing Emacs on Windows 95/98/2K/NT/ME/XP/Vista/Windows 7.  Here's what I did (I used an administrator account.  YMMV).
  1. I wanted emacs in C:\Program Files (x86)\emacs, so I created that folder first
  2. Go here to get the latest emacs version. I got emacs-23.2-bin-i386.zip
  3. Unzip that file and dump its contents into C:\Program Files (x86)\emacs
  4. In Windows Explorer, open C:\Program Files (x86)\emacs\bin, then double click on runemacs.exe
  5. Yay! You have emacs running.  You may wish to add runemacs.exe to your Start menu (drag and drop it there)
Now I copied over from my Ubuntu Linux my .emacs and .emacs.d.  But where to place it?  If you follow Art Lee's instruction step 6, you can control where you want to place those files using the HOME Environment Variable (set in the Windows Control Panel).

On the other hand, why bother?  Especially if you are not running emacs as an administrator.  By default, the HOME will apparently be set as C:\Users\your_user_name\AppData\Roaming anyway, so copy .emacs and .emacs.d into that directory.

Unfortunately for me, coming from Ubuntu, I had ColorTheme installed via apt-get, so it wasn't contained in my .emacs.d.  I have to reinstall that now...

2010-02-27

Moving between windows in Emacs: windmove-default-keybindings

I never used to have such a big monitor, so I made use of switching between buffers a lot. A quick cntl-x-b, etc.

With a big monitor, I find myself using Emacs (in Ubuntu) with the outer window (the thing Ubuntu calls a window anyway) enlarged to full screen. Then within this big window frame, I'll split the frame into smaller "windows" (what Emacs apparently calls "window" I guess) with a cntl-x-2 or cntl-x-3.

You can then switch to the next window with a command like cntl-x-o, and close the window with cntl-x-0, or close all other windows with cntl-x-1. Since I never had more than two windows open in the frame, it never occurred to me to care how to make switching between more windows more efficient.

Now that I do...

Just add (windmove-default-keybindings) to your ~/.emacs and you'll have a nice shift-(arrowkey of your choice) keybindings to move between windows!

More info at http://www.emacswiki.org/emacs/WindMove

Why oh why did I not find this out earlier? :)