Monday, May 23, 2011

Emacs flush duplicated lines function

(defun flush-duplicated-lines (&optional arg)
  "Flush duplicated lines down on buffer. When region is active,
operate on region instead of rest of buffer.

By default it will flush only exatly matched lines only dropping
spaces on begin and end, prefix argument allows specify more
  (interactive "P")

  (flet ((option (name default-value)
                 (if arg
                     (read-from-minibuffer (concat name " (default " (format "%S" default-value) "): "))
    (let ((start (if (region-active-p)
          (end (if (region-active-p)
                 (buffer-end 1)))

          (line-side-ignore-space (not (string-equal
                                        (option "Ignore spaces on sides of line?" t)

      (labels ((shift-to-next-line ()
                                   (and (zerop (forward-line 1))
                                        (<= (line-end-position)
                (chomp (str)
                      (let ((s (if (symbolp str) (symbol-name str) str)))
                        (replace-regexp-in-string "\\(^[[:space:]\n]*\\|[[:space:]\n]*$\\)" "" s)))
                (line-matches (line line-matcher)
                              (and (<= (line-end-position)
                                    (if line-side-ignore-space
                                        (chomp line)
                                    (if line-side-ignore-space
                                        (chomp line-matcher)
               (current-line ()
                             (buffer-substring-no-properties (line-beginning-position)

               (delete-current-line ()

                                    (setf end
                                          (- end
                                             (- (line-end-position)
                                    ;; delete line region
                                    (delete-region (line-beginning-position)
                                    ;; delete newline character
                                    (delete-char 1))

               (delete-lines-matching (line-matcher)
                                        (when (shift-to-next-line)
                                          (loop if (line-matches (current-line)

                                                do (delete-current-line)
                                                else if (not (shift-to-next-line))
                                                return nil)))))
          (goto-char start)
          (loop do (delete-lines-matching (current-line))
                while (shift-to-next-line)))))))

Thursday, May 19, 2011

Ubuntu Linux and Hewlett-Packard LaserJet P1566

So.I have bought this printer as i need laser printer for the PCB and documentation printing.

And directly after connecting it to the Linux box, the problem arised.

The HPLIP drivers package not saw printer, saying "error: No devices found on bus: usb" in console when i tried to do "hp-setup -i".
I tried to pass printer's usb device id as argument to the setup utility to make it see printer and it was detected, but failed to work: any try to access the printer lead to the something like:

error: Unable to communicate with device (code=12): hp:/usb/HP_LaserJet_Professional_P1566?serial=000000000QB03350SI1chp-toolbox(UI)
[3445]: debug: Exception: 2 (Device not found)
error: Unable to open device hp:/usb/HP_LaserJet_Professional_P1566?serial=000000000QB03350SI1c.

Googling not helped, it looks like I first who have this problem with this printer.
Two days i was in searching of solution, even asked a question on Launchpad: Launchpad Question #158013, but in vane.

So today i realized: Smart Install.Smart Install mode is the mode when printer shows self as media drive to the system with drivers for Windows. Unfortunately, by some strange occasion, when printer in this mode, it is unusable with the HPLIP drivers package.

So what you can do with this?
As far as I know for now - you'll need a windows machine to disable Smart Install mode with utility provided on the printer CD, which located in UTIL directory.

I have tried to pass USB with printer to Qemu with windows but had no luck - system hanged.
I have tried to run utility in the Wine, but it will not see the printer.

So, i asked about disabling this feature on launchpad, so it possble will have and answer after some time.

But now it seems you will need a windows machine at least once to use this printer.