├── README.md ├── ffbookmarks └── helm-firefox.el /README.md: -------------------------------------------------------------------------------- 1 | [![MELPA](http://melpa.org/packages/helm-firefox-badge.svg)](http://melpa.org/#/helm-firefox) 2 | [![MELPA Stable](https://stable.melpa.org/packages/helm-firefox-badge.svg)](https://stable.melpa.org/#/helm-firefox) 3 | 4 | 5 | # helm-firefox 6 | 7 | Emacs helm interface for firefox bookmarks. 8 | 9 | ## Dependencies 10 | 11 | You have first to install [helm](https://github.com/emacs-helm/helm) in order to make this working. 12 | If you install from MELPA you don't have to care of this. 13 | 14 | ## Prerequisite 15 | 16 | You will have to set firefox to import bookmarks in his html file bookmarks.html. 17 | (only for firefox versions >=3) 18 | To achieve that, open `about:config` in firefox url toolbar and go to this line: 19 | 20 | user_pref("browser.bookmarks.autoExportHTML", false); 21 | 22 | Double click on this line to enable its value to `true`, you should have now: 23 | 24 | user_pref("browser.bookmarks.autoExportHTML", true); 25 | 26 | NOTE: This is also working in the same way for mozilla aka seamonkey. 27 | 28 | ## Install 29 | 30 | The easiest way is to install from MELPA. 31 | Otherwise put this file in `load-path` compile it and add in your init file: 32 | 33 | (autoload 'helm-firefox-bookmarks "helm-firefox" nil t) 34 | 35 | ## Setup 36 | 37 | On GNU Linux probably you can keep default setting, otherwise you may have to 38 | setup `helm-firefox-default-directory` to some other value. 39 | 40 | ## Create a bookmarklet to jump to helm-firefox from firefox (facultative) 41 | 42 | 1) Create the bookmarklet in firefox: 43 | - Add a bookmark named `ffbookmarks` in your personal bar in firefox. 44 | - Right click on it and add `javascript:location.href='ffbookmarks://localhost'` as url. 45 | 46 | 2) Add the `ffbookmarks` script in a directory of your `PATH`. 47 | 48 | 3) Install [firefox-protocol](https://github.com/thierryvolpiatto/firefox-protocol) 49 | 50 | M-x `firefox-protocol-installer-install` RET `ffbookmarks` RET `/path/to/ffbookmarks` 51 | 52 | Of course as the script use emacsclient you need an emacs session with a server running 53 | along with firefox to make this working. 54 | 55 | Also to come back to firefox when you select a bookmark or abort with C-g this script is using 56 | wmctrl program, so you should install it. 57 | By default the script is assuming the firefox executable is "firefox", to modify this you can add 58 | to your env vars in .profile or .bashrc: 59 | 60 | export FIREFOXEXE="name of your firefox executable" 61 | 62 | -------------------------------------------------------------------------------- /ffbookmarks: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ## Description: Call helm-firefox-bookmarks from firefox or anywhere else. 3 | ## Author:Thierry Volpiatto 4 | ## Commentary: Use firefox-protocol-installer-install to install protocol 5 | ## +from emacs. 6 | # Use this bookmarklet: 7 | # javascript:location.href='ffbookmarks://localhost' 8 | 9 | FIREFOXEXE=$(if [ -z $FIREFOXEXE ]; then echo "firefox"; else echo $FIREFOXEXE; fi) 10 | wmctrl -a emacs 11 | emacsclient -e "(progn (helm-firefox-bookmarks) nil)" > /dev/null 12 | wmctrl -xa $FIREFOXEXE 13 | exit 0 14 | -------------------------------------------------------------------------------- /helm-firefox.el: -------------------------------------------------------------------------------- 1 | ;;; helm-firefox.el --- Firefox bookmarks -*- lexical-binding: t -*- 2 | 3 | ;; Copyright (C) 2012 ~ 2015 Thierry Volpiatto 4 | 5 | ;; Version: 1.1 6 | ;; Package-Requires: ((helm "1.5") (cl-lib "0.5") (emacs "24.1")) 7 | ;; URL: https://github.com/emacs-helm/helm-firefox 8 | 9 | ;; This program is free software; you can redistribute it and/or modify 10 | ;; it under the terms of the GNU General Public License as published by 11 | ;; the Free Software Foundation, either version 3 of the License, or 12 | ;; (at your option) any later version. 13 | 14 | ;; This program is distributed in the hope that it will be useful, 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | ;; GNU General Public License for more details. 18 | 19 | ;; You should have received a copy of the GNU General Public License 20 | ;; along with this program. If not, see . 21 | 22 | 23 | ;;; Code: 24 | (require 'cl-lib) 25 | (require 'helm) 26 | (require 'helm-utils) 27 | (require 'helm-adaptive) 28 | (require 'helm-net) 29 | 30 | 31 | (defgroup helm-firefox nil 32 | "Helm libraries and applications for Firefox navigator." 33 | :group 'helm) 34 | 35 | (defvar helm-firefox-bookmark-url-regexp "\\(https\\|http\\|ftp\\|about\\|file\\)://[^ \"]*") 36 | (defvar helm-firefox-bookmarks-regexp ">\\([^><]+.\\)") 37 | (defvar helm-firefox-history nil) 38 | 39 | (defface helm-firefox-title 40 | '((t (:inherit 'font-lock-type-face))) 41 | "Face used for firefox bookmark titles." 42 | :group 'helm-firefox) 43 | 44 | (defun helm-get-firefox-user-init-dir (directory) 45 | "Guess the default Firefox user directory name." 46 | (with-temp-buffer 47 | (insert-file-contents 48 | (expand-file-name "profiles.ini" directory)) 49 | (goto-char (point-min)) 50 | (prog1 51 | (cl-loop with dir 52 | with atime = 0 53 | while (re-search-forward "Path=" nil t) 54 | for tmpdir = (expand-file-name 55 | (buffer-substring-no-properties 56 | (point) (point-at-eol)) 57 | directory) 58 | for bmkfile = (expand-file-name "bookmarks.html" tmpdir) 59 | for at = (if (file-exists-p bmkfile) 60 | (float-time (nth 5 (file-attributes bmkfile))) 61 | (max atime 0)) 62 | when (> at atime) 63 | do (setq dir tmpdir 64 | atime at) 65 | finally return (file-name-as-directory 66 | (expand-file-name 67 | dir directory))) 68 | (kill-buffer)))) 69 | 70 | (defvar helm-firefox-bookmark-user-directory nil 71 | "The Firefox user directory. 72 | 73 | This variable is set automatically by helm-firefox, you should not 74 | have to modify it yourself. 75 | 76 | Should be located in `helm-firefox-default-directory', you may have 77 | several different directories there if you use different firefox 78 | versions, if the default found by helm-firefox is not the one you want 79 | to use, look at your \"profiles.ini\" file which profile you are 80 | currently using, Firefox use by default the one of the recentest 81 | Firefox installation, it is adviced to use Firefox sync instead of 82 | changing this default value.") 83 | 84 | (defcustom helm-firefox-default-directory "~/.mozilla/firefox/" 85 | "The root directory containing firefox config. 86 | On Mac OS X, probably set to \"~/Library/Application Support/Firefox/\". 87 | 88 | DO NOT use `setq' to configure this variable." 89 | :group 'helm-firefox 90 | :type 'string 91 | :set (lambda (var val) 92 | (set var val) 93 | (setq helm-firefox-bookmark-user-directory 94 | (helm-get-firefox-user-init-dir val)))) 95 | 96 | (defun helm-guess-firefox-bookmark-file () 97 | "Return the path of the Firefox bookmarks file." 98 | (expand-file-name "bookmarks.html" helm-firefox-bookmark-user-directory)) 99 | 100 | (defvar helm-firefox-bookmarks-alist nil) 101 | (defvar helm-source-firefox-bookmarks 102 | (helm-build-sync-source "Firefox Bookmarks" 103 | :init (lambda () 104 | (setq helm-firefox-bookmarks-alist 105 | (helm-html-bookmarks-to-alist 106 | (helm-guess-firefox-bookmark-file) 107 | helm-firefox-bookmark-url-regexp 108 | helm-firefox-bookmarks-regexp))) 109 | :candidates (lambda () 110 | (cl-loop for (bmk . url) in helm-firefox-bookmarks-alist 111 | collect (concat bmk "\n" url))) 112 | :multiline t 113 | :filtered-candidate-transformer 114 | '(helm-adaptive-sort 115 | helm-firefox-highlight-bookmarks) 116 | :action (helm-make-actions 117 | "Browse Url" 118 | (lambda (_candidate) 119 | (let ((urls (helm-marked-candidates))) 120 | (cl-loop for cand in urls 121 | do (helm-browse-url cand)))) 122 | "Copy Url" 123 | (lambda (url) 124 | (kill-new url) 125 | (message "`%s' copied to kill-ring" url))))) 126 | 127 | (defun helm-firefox-bookmarks-get-value (elm) 128 | (assoc-default elm helm-firefox-bookmarks-alist)) 129 | 130 | (defun helm-firefox-highlight-bookmarks (bookmarks _source) 131 | (cl-loop for bmk in bookmarks 132 | for split = (split-string bmk "\n") 133 | collect (cons (concat (propertize 134 | (car split) 135 | 'face 'helm-firefox-title) 136 | "\n" 137 | (cadr split)) 138 | (cadr split)))) 139 | 140 | ;;;###autoload 141 | (defun helm-firefox-bookmarks () 142 | "Preconfigured `helm' for firefox bookmark. 143 | You will have to enable html bookmarks in firefox: 144 | open \"about:config\" in firefox and double click on this line to enable value 145 | to true: 146 | 147 | user_pref(\"browser.bookmarks.autoExportHTML\", false); 148 | 149 | You should have now: 150 | 151 | user_pref(\"browser.bookmarks.autoExportHTML\", true); 152 | 153 | After closing firefox, you will be able to browse your bookmarks." 154 | (interactive) 155 | (helm :sources `(helm-source-firefox-bookmarks 156 | ,(helm-build-dummy-source "DuckDuckgo" 157 | :action (lambda (candidate) 158 | (helm-browse-url 159 | (format helm-surfraw-duckduckgo-url 160 | (url-hexify-string candidate)))))) 161 | :truncate-lines t 162 | :buffer "*Helm Firefox*" 163 | :history 'helm-firefox-history)) 164 | 165 | 166 | (provide 'helm-firefox) 167 | 168 | ;; Local Variables: 169 | ;; byte-compile-warnings: (not cl-functions obsolete) 170 | ;; coding: utf-8 171 | ;; indent-tabs-mode: nil 172 | ;; End: 173 | 174 | ;;; helm-firefox.el ends here 175 | --------------------------------------------------------------------------------