{"id":2214,"date":"2016-04-11T10:00:09","date_gmt":"2016-04-11T15:00:09","guid":{"rendered":"https:\/\/www.foell.org\/justin\/?p=2214"},"modified":"2019-10-21T11:51:12","modified_gmt":"2019-10-21T16:51:12","slug":"emacs-on-osx","status":"publish","type":"post","link":"https:\/\/www.foell.org\/justin\/emacs-on-osx\/","title":{"rendered":"Emacs on OSX"},"content":{"rendered":"<p>So, I started a new job. Besides actually <a href=\"https:\/\/www.foell.org\/justin\/new-job-biking-to-work-i-didnt-die\/\">leaving my home to at least occasionally go into the office<\/a>, the other big change is I&#8217;ve been given a brand-spanking-new MacBook Pro to use (<a href=\"http:\/\/cimbura.com\/2015\/09\/10\/cimbura-com-is-member-of-apple-consultants-network-acn\/\" target=\"_blank\" rel=\"noopener noreferrer\">our shop is a part of the Apple Consultant Network<\/a>).<\/p>\n<p>While using Linux professionally for the last 13 years is sort of coming to an end, Linux certainly isn&#8217;t going away from my life, especially after using it almost exclusively at home for 20 years.<\/p>\n<p>The MacBook is still a BSD unix system at heart &#8211; with some great hardware, and a lovely, albeit sometimes frustrating, user interface laid on top. Mac enthusiasts might abhor that the only application I set to launch on boot is the terminal. This article is not for them, because in old-school fashion I&#8217;m going to cover installing and using Emacs and some other extras in OSX.<\/p>\n<p><!--more--><\/p>\n<h2>Installing Emacs<\/h2>\n<p>Installing Emacs via <a href=\"http:\/\/brew.sh\/\" target=\"_blank\" rel=\"noopener noreferrer\">homebrew<\/a> is very easy so I won&#8217;t go into it, you can follow these instructions: <a href=\"http:\/\/wikemacs.org\/wiki\/Installing_Emacs_on_OS_X#Homebrew\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/wikemacs.org\/wiki\/Installing_Emacs_on_OS_X#Homebrew<\/a><\/p>\n<p>OSX 10.11 (El Capitan) actually includes GNU Emacs 22, but it&#8217;s only the terminal based version. If you want the newest version and a full GUI, follow the homebrew instructions above. If you need to move or rename the old version, you may need to <a href=\"http:\/\/apple.stackexchange.com\/questions\/101328\/file-cant-be-moved-by-root-on-os-x\" target=\"_blank\" rel=\"noopener noreferrer\">keep OSX&#8217;s attributes and latest security layers in mind<\/a>. Rather than moving my old version, I added an alias to my <code>~\/.bashrc<\/code>:<\/p>\n<pre>alias emacs=\"\/usr\/local\/Cellar\/emacs\/24.5\/Emacs.app\/Contents\/MacOS\/Emacs\"<\/pre>\n<p>However, <a href=\"http:\/\/stackoverflow.com\/questions\/7780030\/how-to-fix-terminal-not-loading-bashrc-on-os-x-lion\" target=\"_blank\" rel=\"noopener noreferrer\">OSX&#8217;s bash won&#8217;t read and run<code>~\/.bashrc<\/code><\/a>, only <code>~\/.bash_profile<\/code>, so to my <code>~\/.bash_profile<\/code> I added:<\/p>\n<pre>[[ -s ~\/.bashrc ]] &amp;&amp; source ~\/.bashrc<\/pre>\n<p>In my <code>~\/.bash_profile<\/code> I also added a <code>~\/bin<\/code> directory to my path where I can put custom scripts:<\/p>\n<pre>export PATH=\"~\/bin:$PATH\"<\/pre>\n<p>To shorten up <code>emacs<\/code> I added a shell script called <code>em<\/code> to my <code>~\/bin<\/code> directory:<\/p>\n<pre>#!\/bin\/sh\r\nopen -n -a \/Applications\/Emacs.app \"$@\" &amp;\r\n<\/pre>\n<p>One caution about doing something similar to this is that <code>em<\/code> (edit) is now <em>very<\/em> close to <code>rm<\/code> (remove) since the &#8216;E&#8217; and &#8216;R&#8217; keys are neighbors. Just make sure you know what you&#8217;ve typed before hitting return \ud83d\ude42<\/p>\n<h2>Fix Home\/End Keys<\/h2>\n<p>I&#8217;m not sure why the Home\/End keys don&#8217;t have normal behavior as I&#8217;ve become accustomed to. Here are some fixes I&#8217;ve found that work:<\/p>\n<h3>Home\/End for <a href=\"http:\/\/apple.stackexchange.com\/questions\/16135\/remap-home-and-end-to-beginning-and-end-of-line\" target=\"_blank\" rel=\"noopener noreferrer\">most applications<\/a><\/h3>\n<pre>$ mkdir -p ~\/Library\/KeyBindings\/<\/pre>\n<pre>$ vi ~\/Library\/KeyBindings\/DefaultKeyBinding.dict<\/pre>\n<p>Then add the following:<\/p>\n<pre>{\r\n    \"\\UF729\"  = moveToBeginningOfParagraph:; \/\/ home\r\n    \"\\UF72B\"  = moveToEndOfParagraph:; \/\/ end\r\n    \"$\\UF729\" = moveToBeginningOfParagraphAndModifySelection:; \/\/ shift-home\r\n    \"$\\UF72B\" = moveToEndOfParagraphAndModifySelection:; \/\/ shift-end\r\n}\r\n<\/pre>\n<h3>Home\/End in Terminal<\/h3>\n<p>Open Terminal, then go to Terminal -&gt; Preferences&#8230;<\/p>\n<p>Go to the Profiles section, highlight the terminal profile you use the most, then click the &#8220;Keyboard&#8221; tab. You&#8217;ll probably have to add two new entries for Home and End, but first highlight F1, click edit, then copy the \\033OP action code so you can paste it in the new codes. Click cancel after copying the F1 code.<\/p>\n<p>Click &#8216;+&#8217; to add Home. Choose Key: &#8220;Home&#8221;, Modifier: &#8220;None&#8221;, Action: &#8220;Send Text:&#8221;, and paste in the action code. Click &#8220;Delete One Character&#8221; and then type &#8220;H&#8221;. You should end up with \\033OH for Home. Follow the same procedure for End, but map it to \\033OF.<\/p>\n<h3>Home\/End In Emacs<\/h3>\n<p>Edit your <code>~\/.emacs<\/code> file (you could instead edit it with Emacs and it would be oh so meta).<\/p>\n<pre>$ vi ~\/.emacs<\/pre>\n<p>Add the following:<\/p>\n<pre>; Fix home\/end in OSX\r\n(define-key global-map [home] 'beginning-of-line)\r\n(define-key global-map [end] 'end-of-line)<\/pre>\n<h3>PHP Add-ons<\/h3>\n<p>I wanted to add a PHP Code Sniffer to do syntax checking and documentation\/standards enforcement. To add it via homebrew, I first needed to add the alternate homebrew-php repository. See the <a href=\"https:\/\/github.com\/Homebrew\/homebrew-php\" target=\"_blank\" rel=\"noopener noreferrer\">installation instructions here<\/a>. Then I could install phpcs:<\/p>\n<pre>brew install php-code-sniffer<\/pre>\n<p>I added this because I want to use the official <a href=\"https:\/\/github.com\/WordPress-Coding-Standards\/WordPress-Coding-Standards\" target=\"_blank\" rel=\"noopener noreferrer\">PHP Code Sniffer for WordPress<\/a>.<\/p>\n<p>I installed the Code Sniffer for WordPress from github into my <code>~\/Sites<\/code> directory and then added it to my phpcs configuration by running:<\/p>\n<pre>phpcs --config-set installed_paths \/Users\/jfoell\/Sites\/WordPress-Coding-Standards<\/pre>\n<p>Then I verified that it was installed by running:<\/p>\n<pre>phpcs -i<\/pre>\n<p>The installed coding standards are MySource, PEAR, PHPCS, PSR1, PSR2, Squiz, Zend, WordPress, WordPress-Core, WordPress-Docs, WordPress-Extra and WordPress-VIP<\/p>\n<h3>PHP Code Sniffer in Emacs via MELPA and Flycheck<\/h3>\n<p>I added <a href=\"http:\/\/stable.melpa.org\/#\/getting-started\" target=\"_blank\" rel=\"noopener noreferrer\">MELPA stable packages<\/a> to my <code>~\/.emacs<\/code> file (see their installation instructions), then updated MELPA from within Emacs:<\/p>\n<pre>M-x package-list-packages RET<\/pre>\n<p>Then I installed the flycheck extension (which will use PHP CodeSniffer to do on-the-fly syntax checking):<\/p>\n<pre>M-x package-install RET flycheck RET<\/pre>\n<p>Then I added the following default phpcs standard setting and init hook to my <code>~\/.emacs<\/code> file:<\/p>\n<pre>(custom-set-variables\r\n '(flycheck-phpcs-standard \"WordPress\")\r\n)\r\n\r\n(add-hook 'after-init-hook #'global-flycheck-mode)<\/pre>\n<h2>Other Emacs and Terminal Goodies<\/h2>\n<p>To add <a href=\"https:\/\/www.emacswiki.org\/emacs\/TabBarMode\" target=\"_blank\" rel=\"noopener noreferrer\">Tab Bar Mode<\/a> support, I cloned the <a href=\"https:\/\/github.com\/dholm\/tabbar\" target=\"_blank\" rel=\"noopener noreferrer\">Aquamacs tabbar project<\/a> into <code>~\/.elisp\/tabbar<\/code>. Then I added these lines to my <code>~\/.emacs<\/code> file to load the tabbar library and start tab bar mode automatically:<\/p>\n<pre>\r\n;; Load custom tabbar mode\r\n(load-file \"~\/.elisp\/tabbar\/tabbar.el\")\r\n(tabbar-mode)\r\n<\/pre>\n<p>Lastly, here&#8217;s a great article on getting the terminal prompt and output to look a little nicer: <a href=\"http:\/\/osxdaily.com\/2013\/02\/05\/improve-terminal-appearance-mac-os-x\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/osxdaily.com\/2013\/02\/05\/improve-terminal-appearance-mac-os-x\/<\/a><\/p>\n<p>Happy Hacking!<\/p>\n<div class='kindleWidget kindleLight' ><img decoding=\"async\" src=\"https:\/\/www.foell.org\/justin\/wp-content\/plugins\/send-to-kindle\/media\/white-15.png\" \/><span>Send to Kindle<\/span><\/div>","protected":false},"excerpt":{"rendered":"<p>So, I started a new job. Besides actually leaving my home to at least occasionally go into the office, the other big change is I&#8217;ve been given a brand-spanking-new MacBook Pro to use (our shop is a part of the Apple Consultant Network). While using Linux professionally for the last 13 years is sort of&hellip; <a href=\"https:\/\/www.foell.org\/justin\/emacs-on-osx\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Emacs on OSX - retrogrouchery at it's finest","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1,8,22],"tags":[116,12,166,152,151],"class_list":["post-2214","post","type-post","status-publish","format-standard","hentry","category-business","category-ubuntu","category-wordpress","tag-apple","tag-emacs","tag-linux","tag-mac","tag-osx"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts\/2214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/comments?post=2214"}],"version-history":[{"count":12,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts\/2214\/revisions"}],"predecessor-version":[{"id":3580,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/posts\/2214\/revisions\/3580"}],"wp:attachment":[{"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/media?parent=2214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/categories?post=2214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.foell.org\/justin\/wp-json\/wp\/v2\/tags?post=2214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}